2013-12-13 56 views
1

我不能得到它,爲什麼它不工作PHP: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 

爲什麼每次我得到空的結果?此代碼中有任何錯誤。請幫忙。

+0

什麼價值'$ searchdata'有哪些? –

+0

可能有很多錯誤,你沒有提供足夠的信息。 – Zarathuztra

+0

$ searchdata的值爲'akbar' –

回答

0

MySQL要求您使用buffered query,因爲在取出所有行之前,rowCount()方法無法知道結果集中有多少行。

0

試試這個..

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

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