duanbi1983 2014-07-22 19:08
浏览 32

mysqli准备查询无法正常工作

I have this table:

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;

This is in the table:

INSERT INTO `comment` VALUES (0,'Bernard','user@domain.com','This is a comment',1,'2014-07-22 17:34:24',0);

This php code spits out "foo" and nothing else:

<?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';

Why is this failing, and why is it not throwing any errors?

  • 写回答

1条回答 默认 最新

  • douzhao7014 2014-07-22 19:14
    关注

    As for the query, you should replace the first 0 a null to let the auto-increment work:

    INSERT INTO `comment` VALUES (NULL,'Bernard','user@domain.com','This is a comment',1,'2014-07-22 17:34:24',0); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题