Home >Backend Development >PHP Tutorial >为啥我这个预处理语句执行不了呢

为啥我这个预处理语句执行不了呢

WBOY
WBOYOriginal
2016-06-23 13:37:27967browse

$mysqli= new mysqli("localhost","root","123456","xsphpdemo");
if(mysqli_connect_errno()){
echo "连接失败
".mysqli_connect_error();
}

$stmt=$mysqli->prepare("select id name price num desn from shop where id>?");

$stmt->bind_param("i",$id);
$stmt->bind_result($id,$name,$price,$num,$desn);
$id="10";
$stmt->execute();
$stmt->store_result();
while($stmt->fetch()){
echo "$id -- $name -- $price -- $num -- $desn 
";
}
echo $stmt->num_rows;
$stmt->close();
执行Var_dump("select id name price num desn from shop where id>?")
布尔型值是假
好像$mysqli->prepare()语句执行不成功,不知道为啥


回复讨论(解决方案)

"select `id`, `name`, `price`, `num` ,`desn` from shop where id>?"

echo $stmt->error;  有错误信息吗

echo $stmt->error;  有错误信息吗


没有,我按楼上的加了引号,加入var_dump($stmt)之后显示是对象了,可是一执行错误又变成------>


echo $stmt->error;  有错误信息吗


没有,我按楼上的加了引号,加入var_dump($stmt)之后显示是对象了,可是一执行错误又变成------>
我没用过mysqli,但你这句是不是错了
$stmt->bind_param("i",$id);


是不是应为
$stmt->bind_param(1,$id);

字段没有隔开
$stmt=$mysqli->prepare("select id, name, price, num, desn from shop where id>?");

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