Setting the TIME field to NULL with Zend_Db

I came across what looks like an odd problem with a driver Zend_Dbor PHP PDO MySQL, which may stem from my ignorance of these two.

Suppose I have a MySQL table with NULLcapable TIME. If I run such a query in a MySQL client:

UPDATE mytable SET mytime = NULL WHERE id = 1;

Everything works as expected, and the mytime field will hold NULLas the value after this request.

However, if I run the same request in PHP through Zend_Db_Adapter, the mytime field will be set to '0:0:0'after such a request:

$db->getConnection()->exec('UPDATE mytable SET mytime = NULL WHERE id = 1');

How to set the TIME field to NULL?

I am using PHP5.3 with the PDO driver MySQL, Zend Framework 1.11 and MySQL 5.1.

+3
source share
2

, :

$db->getConnection()->exec('UPDATE mytable SET mytime = NULL WHERE id = 1');

. .

Caveat

NOT NULL, NULL , NULL 00:00:00, ,

CREATE TABLE `test` (
    `time` datetime NOT NULL
);

NULL 00:00:00.

, . datetime, NOT NULL NULL, 0000-00-00 00:00:00.

. Mysql NULL NUT NULL, , MySQL SQL_MODE STRICT_ALL_TABLES: . fooobar.com/questions/1905533/....

, NULL, :

CREATE TABLE `test` (
    `time` datetime DEFAULT NULL
);

NULL.

+1

new Zend_Db_Expr('NULL') NULL:

$zend_null = new Zend_Db_Expr('NULL');
$db->getConnection()->exec("UPDATE mytable SET mytime = $zend_null WHERE id = 1");
0

All Articles