Home >Backend Development >PHP Tutorial >php 预编译查询始终fetch不到数据

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

WBOY
WBOYOriginal
2016-06-23 14:21:011030browse

php prepare 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天了....谢谢了

回复讨论(解决方案)

代码看上去没有问题
但如果直接复制你的代码就无法通过语法检查

http://www.php.net/manual/en/mysqli.prepare.php

http://xiaobo-liu.iteye.com/blog/1288008

settype($seach_id, "integer");
可以省略

什么输出都没有?先确认进入if了没有?

可能是自己机器某些地方的配置有问题,  最后决定启用PDO了, 反正早晚都需要学习新知识
而且PDO确实要比MySQli 要好, 这个问题就算解决了吧
PDO用熟练了很方便, 而且PDO的prepare 就没有上面的问题, 应该是自己配置的问题

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn