2013-06-20 24 views
1

我有一個問題,真的讓我感到震驚我創建了一個網站,我希望我的用戶首先連接到該網站,然後他們將信息填充到表中,然後保存數據,並通過ID 重新顯示他們這是什麼,我特穎做可捕捉的致命錯誤:類PDoCtatement的對象無法轉換爲D中的字符串

$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 
+1

什麼是'$ id =#SESSION {idCommercant}'?什麼是'45'? – PeeHaa

+0

我想問什麼是第45行 –

回答

1

錯誤消息是很明顯的:對你正在嘗試投射的線條爲$response o投入字符串。通過試圖迴應它或連接或其他。你必須讓數據陣列進行反應,然後使用它:

$row = $reponse->fetch(); 

另外請注意,使用模具()一般,尤其是無用與PDO,可自行死亡被禁止,並且更好的方式執行它比如果你手動殺死它。

-1

你的第一行應該讀的$ id = $ _SESSION [「idCommercant」(我想)

目前的情況是單行註釋是等號(=)後立即開始。在下一行開始執行,並將$ response(PDOStatement)的值賦給$ id。

在最後一行中,您嘗試將此參數作爲參數傳遞給$ response-> execute(),該參數需要一個字符串數組,但會給出一個帶有PDOStatement的數組。它不能被轉換,因此是錯誤的。

相關問題