2016-03-10 68 views
0

請幫助我。 PHP在boolean'`調用成員函數fetch()布爾型(xampp)

$sql = $pdo->prepare("select id,name,biography from authors where id=?"); 
$data = array($_POST['id']); 
$result = $sql->execute($data); 
$str=$result->fetch(PDO::FETCH_ASSOC);` 

返回我的錯誤「調用一個成員函數取()查詢作出成功,因爲 的var_dump($結果)=布爾(真)。

同樣的結果我有: $sql = $pdo->prepare("select id,name,biography from authors where id=:id"); $result = $sql->execute(array(':id'=>$_POST['id'])); $str=$result->fetch(PDO::FETCH_ASSOC);

查詢

$pdo->query("select id,name,biography from authors");

有人成功

回答

0

​​返回true或false,這就是爲什麼你的錯誤。你應該得到像這樣的結果:

$sql = $pdo->prepare("select id,name,biography from authors where id= ?"); 
$data = array($_POST['id']); 
$sql->execute($data); 
$str=$sql->fetch(PDO::FETCH_ASSOC); 
相關問題