开发者

Inserting current date to MySql using Zend Date

I have a website based on Zend Framework. There is a form for users to fill in and the entered data is inserted in the database.

The users don't enter the date/time. I would like to populate the data value based on the current date/time开发者_高级运维 . The date field is of type datetime.

i'm constantly getting the following error message:

Notice: Array to string conversion in D:\wamp\www\CNFSORG\library\Zend\Db\Statement\Pdo.php on line 228

I have tried doing the following:

<?php $date = new Zend_Date(); ?>

also tried doing:

<?php $date = new Zend_Db_Expr('NOW()'); ?>
<?php $date = new Zend_Db_Expr('CURDATE()'); ?>

I would be very grateful if someone could point me towards the right direction.

thanks in advance...


The Correct answer is

<?php $date = new Zend_Db_Expr('NOW()'); ?>

You can try create a current timestamp from php with something like that

<?php  $date = new \DateTime(); ?>


Well, i'v done this for SqlServer, but i think that for MySql you just need to change the db-expression for the one you want.

$this->_colocation = new Application_Model_Colocation();
$solicitacao = $this->_colocation->find($post['hdnIdSolicitacao'])->current();
$solicitacao->data_chegada = new Zend_Db_Expr('getdate()');
$solicitacao->save();

Hope it helps.


In your class of table use this code:

    $tme =new Zend_Date();
    $data['tme']=$tme->now();
    $this->insert($data);

If you have a column with tme name and type of datetime , this code will do what you want!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜