我有这张桌子:
CREATE TABLE `comment` (
`id` int(11) unsigned NOT NULL,
`name` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`comment` text,
`article_id` int(11) unsigned NOT NULL DEFAULT '1',
`date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`deleted` tinyint(3) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这在表格中:
INSERT INTO `comment` VALUES (0,'Bernard','user@domain.com','This is a comment',1,'2014-07-22 17:34:24',0);
这个PHP代码吐出“foo”而没有别的:
<?php
error_reporting(E_ALL);
echo 'foo';
$db = new mysqli("localhost", 'root', '', 'ggs');
$query = $db->prepare("SELECT * FROM `comment` `c` WHERE `c`.`article_id` = ? AND `c`.`deleted` = 0 ORDER BY `c`.`date` ASC");
if (!$query) {
echo $db->errno . " - Could not prepare SQL statement: " . $db->error;
} else {
$query->bind_param('i', 1);
$query->execute();
echo json_encode($query->fetch());
}
echo 'bar';
为什么会失败,为什么不抛出任何错误?
答案 0 :(得分:0)
对于查询,您应该将第一个0替换为null以使自动增量工作:
INSERT INTO `comment` VALUES (NULL,'Bernard','user@domain.com','This is a comment',1,'2014-07-22 17:34:24',0);