日期:2014-05-17  浏览次数:20356 次

php 预编译查询始终fetch不到数据

include ('../db/MySqlConnect.php');
$conn = new MySqlConnect();
$mysqli = $conn->getConnection();
$sql = 'select id, username, password from admin where id = ?';
$seach_id = 1;
settype($seach_id, "integer");
if($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param('i', $seach_id);
$stmt->execute();
$stmt->bind_result($rs_id, $rs_name, $rs_password);
if($stmt->fetch() == NULL) {
echo 'no result';
} else {
 printf('id:%s, name:%s, password:%s <br/>', $rs_id, $rs_name, $rs_password);
}
$stmt->close();
$mysqli->close();
}

SQL语句明明可以查询出来数据, 我使用PHP的非预编译语句($result = $mysqli->query($query);)也可以查询出来记录, 就是上面的查询代码始终在fetch出抓取不到数据,我的PHP版本是php-5.2.5-x64, 环境是64位的Win7, 有遇到过的朋友或知道的能给分析一下么, 我已经困扰2天了....谢谢了
php prepare fetch

------解决方案--------------------
代码看上去没有问题
但如果直接复制你的代码就无法通过语法检查
------解决方案--------------------
http://www.php.net/manual/en/mysqli.prepare.php
------解决方案--------------------
http://xiaobo-liu.iteye.com/blog/1288008
------解决方案--------------------
settype($seach_id, "integer");
可以省略
------解决方案--------------------
什么输出都没有?先确认进入if了没有?