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

时间:2013-12-13 02:51:05

标签: php mysql pdo

我无法理解为什么它不起作用

$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 PARAMS返回此

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

为什么每次我都得到空的结果?这段代码有什么问题。请帮忙。

2 个答案:

答案 0 :(得分:0)

MySQL要求您使用buffered query,因为rowCount()方法在获取所有行之前无法知道结果集中有多少行。

答案 1 :(得分:0)

试试这个..

$rowCount = $pdo->query('select count(*) from blah')->fetchColumn(); 

 if(count($rowCount) > 0)
 {
       //Your code here
 } else {
     die();
 }
相关问题