Inserting NOW() into Database with CodeIgniter's Active Record

后端 未结 11 1007
傲寒
傲寒 2020-12-01 02:15

I want to insert current time in database using mySQL function NOW() in Codeigniter\'s active record. The following query won\'t work:

$data = array(
                


        
11条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 03:14

    Unless I am greatly mistaken, the answer is, "No, there is no way."

    The basic problem in situations like that is the fact that you are calling a MySQL function and you're not actually setting a value. CI escapes values so that you can do a clean insert but it does not test to see if those values happen to be calling functions like aes_encrypt, md5, or (in this case) now(). While in most situations this is wonderful, for those situations raw sql is the only recourse.

    On a side, date('Y-m-d'); should work as a PHP version of NOW() for MySQL. (It won't work for all versions of SQL though).

提交回复
热议问题