Jump to content

Zend_Db_Adapter insert() issue.


trq

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.