Как выполнить MySQL NOW() при вставке с ActiveRecord в CodeIgniter

Способ первый:

Because CodeIgniter’s ActiveRecord class automatically escapes the input to insert(), just passing through “now()” won’t work. The best thing to do is just call PHP’s date() function and insert the date in manually in the correct format.
$data = array(
'created' => date('Y-m-d H:i:s')
Alternatively, you could run the SQL query yourself by running the $this->db->query() command - but it’s much easier to just put in the date manually!

Способ 2:

MySQL functions are non-standard and so it breaks support for other database types (which is one of the biggest reasons for database abstraction in the first place).
Doing it via PHP as предложено выше is the best option, or you can do this:
Setting FALSE in the 3rd parameter tells ActiveRecord not to escape your value.

No comments:

Post a Comment