trq Posted July 20, 2009 Share Posted July 20, 2009 I have an array ($data) that for the moment looks like.... Array ( [name] => foo [pass] => 5d41402abc4b2a76b9719d911017c592 [salt] => 5d41402abc4b2a76b9719d911017c592 [role] => 1 [created_at] => 21/07/2009 9:03:09 AM [updated_at] => 21/07/2009 9:03:09 AM ) This represents every column within my tbl_user table. However, when I try to execute an insert query..... //return $data; return $this->_db->insert('tbl_user', $data); I get the following error. Message: SQLSTATE[HY000]: General error: 10007 Cannot insert the value NULL into column 'updated_at', table 'auscorp2.dbo.tbl_user'; column does not allow nulls. INSERT fails. [10007] (severity 5) [(null)] $this->_db is an instance of Zend_Db_Adapter and I am using mssql. updated_at is of type datetime in my database. I can post my backtrace if its required. If I allow NULL's into my database the insert works but the created_at and updated_at columns both show up as NULL. I'm at a loss. Link to comment https://forums.phpfreaks.com/topic/166712-zend_db_adapter-insert-issue/ Share on other sites More sharing options...
trq Posted July 20, 2009 Author Share Posted July 20, 2009 Ok, so Ive figured out that if I create my date using Zend_Db_Expr('GETDATE()') instead of php's date('d/m/Y G:i:s A') I can get this working, however, this isn't ideal. I'm building a simple Orm and the created_at and updated_at columns are added to a model via a behavior plugin that I would obviously like to keep RDBM independent. eg; My plugin now looks like.... <?php class This_Orm_Behavour_Timestampable implements This_Orm_Interface_Behavour { public function __construct(This_Orm_Entity $object) { $object->setColumn('created_at', array('type' => 'datetime', 'default' => new Zend_Db_Expr('GETDATE()'))); $object->setColumn('updated_at', array('type' => 'datetime', 'default' => new Zend_Db_Expr('GETDATE()'))); } } While ideally I would like it to be.... <?php class This_Orm_Behavour_Timestampable implements This_Orm_Interface_Behavour { public function __construct(This_Orm_Entity $object) { $object->setColumn('created_at', array('type' => 'datetime', 'default' => date('d/m/Y G:i:s A'))); $object->setColumn('updated_at', array('type' => 'datetime', 'default' => date('d/m/Y G:i:s A'))); } } Is there any way to tell the Zend_Db_Adapter what column types I'm trying to insert too? Link to comment https://forums.phpfreaks.com/topic/166712-zend_db_adapter-insert-issue/#findComment-879092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.