[英]Call to a member function fetch() on boolean (xampp)
Help me please. 请帮帮我。 PHP returned me error 'Call to a member function fetch() on boolean'`
PHP向我返回错误“在布尔值上调用成员函数fetch()”
$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);`
The query was made successfully because var_dump($result)=bool(true). 由于var_dump($ result)= bool(true),所以查询成功完成。
The same result I have with: $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);
我得到的结果相同:
$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);
$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);
Query 询问
$pdo->query("select id,name,biography from authors");
was made successful 成功了
execute()
returns true or false, thats why you get the error. execute()
返回true或false,这就是您收到错误的原因。 You should fetch results something like this: 您应该获取如下结果:
$sql = $pdo->prepare("select id,name,biography from authors where id= ?");
$data = array($_POST['id']);
$sql->execute($data);
$str=$sql->fetch(PDO::FETCH_ASSOC);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.