可捕获的致命错误:无法将类PDOStatement的对象转换为D中的字符串 [英] Catchable fatal error: Object of class PDOStatement could not be converted to string in D

查看:250
本文介绍了可捕获的致命错误:无法将类PDOStatement的对象转换为D中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题确实使我担心,我创建了一个网站,我希望我的用户首先连接到该网站,然后他们将信息填充到表中,然后保存数据并按ID重新显示它们 这就是我要做的事情

i have a problem that really warried me i create a website and I want my users first connect to the site, and then they fill information in a table, and then save the data and redisplay them by id this is what i'm teying to do

$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对象转换为字符串.通过尝试回显它或连接它或其他任何东西.您必须从响应中获取数据数组,然后使用它:

The error message is pretty obvious: on the line of 45 you are trying to cast $response object into string. by trying either to echo it or concatenate or whatever. You have to get a data array out of response and then use it:

$row = $reponse->fetch();

还要注意,通常禁止使用die(),特别是对于PDO来说是无用的,因为PDO可以自行死亡,并且其执行方式要比手动杀死它更好.

Also note that using of die() is prohibited in general and especially useless with PDO which can die by itself, and perform it way better than if you kill it manually.

这篇关于可捕获的致命错误:无法将类PDOStatement的对象转换为D中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆