可捕获的致命错误:类PDOStatement的对象无法在D中转换为字符串


Catchable fatal error: Object of class PDOStatement could not be converted to string in D

我有一个问题,我真的担心我创建一个网站,我希望我的用户首先连接到网站,然后他们填写表格中的信息,然后保存数据,并通过id重新显示它们这就是我要做的

$id=#SESSION{idCommercant}
//$mail=$_SESSION['_mail'];
$reponse = $bdd->prepare("SELECT * FROM produit, produit_commerce, commerce, commercant
where produit_commerce.idmagasin=commerce.idMagasin
and produit.idProduit=produit_commerce.idproduit
and  commerce.idCommercant= commercant.idCommercant
and  commercant.idCommercant= :id  ;");
$reponse->execute(array(':id'=>$id)) or die(print_r($reponse->errorInfo()));

但是这会返回以下错误:

Catchable fatal error: Object of class PDOStatement could not be converted to string in D:'wamp'www'it_technology'Affichage'essai.php on line 45

错误消息非常明显:在第45行,您试图将$response对象转换为字符串。通过尝试回显或连接或其他方法。你必须从响应中获取一个数据数组,然后使用它:

$row = $reponse->fetch();

还要注意die()通常是禁止使用的,对于PDO尤其没用,因为PDO可以自己死亡,并且比手动杀死它要好得多。

你的第一行应该是$id= $_SESSION[' idcommerant '](我想)

现在在=符号后面开始了一行注释。执行将在下一行继续,并将$response(一个PDOStatement)的值赋给$id。

在最后一行中,您尝试将此作为参数传递给$response->execute(),它期望一个字符串数组,但给出了一个带有PDOStatement的数组。