[英]PHP:PDO Why this code is not working?
我不明白为什么它不起作用
$q1=$conn->prepare('select * from users where username = :data');
$q1->bindParam(':data',$searchdata);//$searchdata is having the value
$q1->execute();
if($q1->rowCount()<1)
{
die('NO results found');
}
$row=$q1->fetch(PDO::FETCH_ASSOC);
echo $row['user_id'];
调试转储参数返回此
select * from users where match(username) against(:searchd) Params: 1 Key: Name: [8] :searchd paramno=-1 name=[8] ":searchd" is_param=1 param_type=2
为什么每次我得到空结果? 此代码中有任何错误。 请帮忙。
MySQL要求您使用缓冲的查询 ,因为在获取所有行之前, rowCount()
方法无法知道结果集中有多少行。
尝试这个..
$rowCount = $pdo->query('select count(*) from blah')->fetchColumn();
if(count($rowCount) > 0)
{
//Your code here
} else {
die();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.