我试图使用Zend框架而不使用MVC结构,特别是Db_Table类.
我创建了几个代表我的数据库表的类,即
class DBTables_Templates extends Zend_Db_Table_Abstract
{
protected $_name = "templates";
}
Run Code Online (Sandbox Code Playgroud)
当我尝试实例化这个类(它被包括在内)时,我收到以下错误:
致命错误:未捕获异常'Zend_Db_Table_Exception',消息'找不到DBTables_Templates的适配器'
有谁知道我如何为Db_Table要使用的类创建和包含数据库适配器?
任何指针都非常感谢!我使用的是最新版本的ZF.
我有一个复杂的数据库设计,包含视图,关系等.我们决定从标准的Zend_db切换到ORM.我成功地整合了zend 1.11和doctrine 2.1.所有教程都解释了如何通过手写类创建整个数据库.但是现有数据库中有数据呢?我再次搜索并发现我必须使用以下命令
php orm:convert-mapping --from-database php path/where/you/want/to/store/mapping/classes
Run Code Online (Sandbox Code Playgroud)
当我为一个只有3个表且没有任何关系的简单数据库执行此操作时,上述命令可以很好地工作.
但是当我尝试在我的数据库上使用相同的命令时,它会抛出一个异常
[Doctrine\ORM\Mapping\MappingException]
Property "employeeid" in "Organization_has_employees" was already declared, but it must be
declared only once
Run Code Online (Sandbox Code Playgroud)
我更改了所有的字段名称,以便在任何表中都没有重复的名称,但仍然没有运气.
请帮我解决一下这个.我打破了我的头超过3天.
KARTHIK
我有以下代码:
public function checkLoginDetails($email, $password) {
$select = $this->select ();
$select->where ( "password=?", md5($password) );
$select->where ( "email=?", $email );
return $this->fetchRow($select);
}
Run Code Online (Sandbox Code Playgroud)
电子邮件和密码直接来自用户.我是否需要使用mysql_real_escape_string过滤电子邮件,或者Zend DB是否为我做了?
谢谢!
有没有办法通过Zend\Db和/或TableGateway insert()/ update()语句在ZF2(2.0.0beta4)的当前版本中包含NOW()等MySQL表达式?
以下是邮件列表中的相关帖子,但尚未得到解答:http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Expr-and-Transactions-in-ZF2- DB-td4472944.html
似乎ZF1使用了类似的东西:
$data = array(
'update_time' => new \Zend\Db\Expr("NOW()")
);
Run Code Online (Sandbox Code Playgroud)
通过Zend\Db\Sql\Expression查看后我尝试了:
$data = array(
'update_time' => new \Zend\Db\Sql\Expression("NOW()"),
);
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
Catchable fatal error: Object of class Zend\Db\Sql\Expression could not be converted to string in /var/www/vendor/ZF2/library/Zend/Db/Adapter/Driver/Pdo/Statement.php on line 256
Run Code Online (Sandbox Code Playgroud)
按照这里的建议:http://zend-framework-community.634137.n4.nabble.com/ZF2-beta3-Zend-Db-Sql-Insert-new-Expression-now-td4536197.html我目前正在设置使用PHP代码约会,但我宁愿使用MySQL服务器作为日期/时间的单一事实来源.
$data = array(
'update_time' => date('Y-m-d H:i:s'),
);
Run Code Online (Sandbox Code Playgroud)
谢谢,我感谢任何输入!
基本问题如何从表映射器中获取"类型"列作为整数值?
我有一个运行网站的PHP Zend Framework 1.12应用程序.MySQL内部是多个具有多列的表.在两个表中我使用SET类型.该列名为"type"和"set('LOCAL','EXTERNAL')'.请不要将此字段类型与ENUM混淆!
到目前为止没有问题,查询表并将类型列提取为INT或STRING不是问题:
$Sql = $Db->select()->from('tablename', ['type_as_int' => new \Zend_Db_Expr('type+0')]); //returns INT (if both are selected: 3)
$Sql = $Db->select()->from('tablename', ['type']); //returns STRING (if both are selected: LOCAL,EXTERNAL)
Run Code Online (Sandbox Code Playgroud)
但是,在此应用程序中还有表映射程序,可以扩展Zend_Db_Table_Abstract.映射器内部存在'find()'方法.默认内置于摘要中以按主键查找记录.但是..当我使用该对象获取记录时,我在populate方法中找到以下响应:
array([type] => LOCAL,EXTERNAL)
Run Code Online (Sandbox Code Playgroud)
手动查询(并自己定义列)将是一个选项($ this-> select() - > from ...),但是不是更优雅的方式吗?
(我知道我使用的是旧版本的ZF,但此时升级会花费太多时间.)
我有以下代码
$result = $handle->select()->from('store_details')
->where('store_details.store_id=?', $id)
->columns('store_details.store_name');
//->query(ZEND_DB::FETCH_OBJ);
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,选择整行,而不仅仅是我想要的列.这是__toString的输出
SELECT `store_details`.*, `store_details`.`store_name`
FROM `store_details` WHERE (store_details.store_id=8)
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
在以下代码中:
$selectColumns= array('user_id.user_email', // inner join the data from user_id and user_details
'user_details.first_name',
'user_details.last_name');
$result = $handle->select()->from('user_id', $selectColumns)
->where('user_id.uid=?', $uid)
->join('user_details', 'user_id.uid = user_details.uid')
->query(ZEND_DB::FETCH_OBJ);
Run Code Online (Sandbox Code Playgroud)
Zend选择表中的所有列,而不仅仅是请求的列.
我怎样才能选择一些?
我正在使用Zend Framework与MySQL,Apache和Ubuntu 9.04.
我试图将NULL值插入数据库,如下所示:
$personObj->setPersonId( '1' );
$personObj->setPersonEmail('NULL');
$personObj->save();
Run Code Online (Sandbox Code Playgroud)
但是'NULL'作为字符串存储在数据库中而不是NULL.
我用这个时:
$personObj->setPersonId( '1' );
$personObj->setPersonEmail(NULL);
$personObj->save();
Run Code Online (Sandbox Code Playgroud)
但没有任何反应,之前的条目没有改变.
如何在MySQL中插入NULL值?
我用它来检索数据库连接atm.
$db = Zend_Db_Table::getDefaultAdapter();
Run Code Online (Sandbox Code Playgroud)
我在我的配置中设置了这样:
resources.db.adapter = pdo_mysql
resources.db.isDefaultTableAdapter = true
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = password
resources.db.params.dbname = db
resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler
Run Code Online (Sandbox Code Playgroud)
我想将所有内容输出到sql.log中.这可以应用于默认适配器吗?例如通过设置,所以我可以在生产环境中忽略它?
非常感兴趣.
我确实看过:如何使用Zend_Db启用SQL输出到日志文件?但它似乎没有涵盖我的问题.
/马库斯
使用PHPUnit创建测试时遇到一些问题.
这是我的设置:
protected function setUp()
{
$serviceManager = Bootstrap::getServiceManager();
$this->mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$this->mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface');
$this->mockDriver->expects($this->any())->method('checkEnvironment')->will($this->returnValue(true));
$this->mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($this->mockConnection));
$this->mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
$this->mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$this->mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($this->mockStatement));
$this->adapter = new Adapter($this->mockDriver, $this->mockPlatform);
$this->sql = new Sql($this->adapter);
$mockTableGateway = $this->getMock('Zend\Db\TableGateway\TableGateway', array(), array(), '', false);
$maiFormuleRevisionTable = $this->getMockBuilder('Maintenance\Model\BDD\PMaiFormulerevisionTable')
->setMethods(array())
->setConstructorArgs(array($mockTableGateway, $this->adapter, $this->sql))
->getMock();
$maiFormulerevisionService = $this->getMockBuilder('Maintenance\Service\Model\PMaiFormulerevisionService')
->setMethods(array())
->setConstructorArgs(array($maiFormuleRevisionTable))
->getMock();
$this->assertTrue($maiFormulerevisionService instanceof PMaiFormulerevisionService);
$this->controller = new RevisionsController($maiFormulerevisionService);
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$config = $serviceManager->get('Config');
$routerConfig = …Run Code Online (Sandbox Code Playgroud)