在下面的代码中使用SQL:
public function saveOrder() {
$id = $this->getUserId();
$this->db->query("INSERT INTO orders VALUES (null, '$id', '$this->basket_lines', '$this->total', NOW() )");
return $this->db->id();
}
上面最后一列是 DATETIME
字段,数据库中的结果保持默认为 0000-00-00 00:00:00
.
我试过列格式为 timestamp
也用过:
ALTER TABLE `content ` CHANGE `date` `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
来自另一个帖子,但无济于事。
谁能找出问题所在?
谢谢
编辑:顺便说一句,我正在使用
从 DB 类中转义我的 SQL 语句 $this->SQL = $this->mysqli->real_escape_string($SQL);
$this->result = $this->mysqli->query($SQL);
编辑 2:我现在使用 来逃避预查询
$i=mysql_real_escape_string($id);
$b=mysql_real_escape_string($this->basket_lines);
$t=mysql_real_escape_string($this->total);
$this->db->query("INSERT INTO orders VALUES (null, '$i', '$b', '$t', NOW() )");
还是不行,这一切都很奇怪?
最佳答案
您没有转义任何数据。您的数据很可能会打乱您的其余查询。您也很可能对 SQL 注入(inject)持开放态度。至少,您应该使用 mysql_real_escape_string()
, 但最好使用 prepared queries with PDO .
关于php - MySQL PHP : Geting 0000-00-00 00:00:00 when using NOW() in a datetime column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10029999/