how to use mysql now() function in cakephp for date fields?

后端 未结 5 1701
我寻月下人不归
我寻月下人不归 2021-01-21 12:02

I have this code in my cakephp project:

$this->data[\'MyObject\'][\'expire_date\'] = \'NOW()\';

and...

$this->MyObject-&g         


        
5条回答
  •  梦毁少年i
    2021-01-21 12:25

    For CakePHP 3 (in case someone's searching), you'd need to use the SQL functions:

    $query = $this->Example->query();
    $query
        ->insert(['created','id'])
        ->values(array(
            'created' => $query->func()->now(),
            'id' => $id,
        ));
    $result = $query->execute();
    

    Sources:

    • query-builder.html#using-sql-functions

提交回复
热议问题