PHP:PDO为什么这个代码不起作用


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

DEBUG DUMP PARMS返回此

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();
 }