2013-10-11 68 views
0

我有選擇從號碼列表一個PIN,然後該PIN分配給用戶,並將其插入到另一個表的簡單查詢:捕獲的致命錯誤:類stdClass的的對象不能被轉換成字符串

$sth = $this->db->query("SELECT available_pins FROM pin_list ORDER BY RAND() LIMIT 0,1 ;"); 
$pinarray = $sth->fetch(); 
$this->user_pin = $pinarray; 

$sth = $this->db->prepare("INSERT INTO users (user_email, user_pin) VALUES(:user_email, :user_pin) ;"); 
$sth->execute(array(':user_email' => $this->user_email, ':user_pin' => $this->user_pin)); 

但是,這會產生一個可捕獲的致命錯誤:類stdClass的對象無法轉換爲字符串,任何想法?

附加信息

$ sth->執行(陣列給出了錯誤,available_pins使用MEDIUMINT(6),它是隨機的6位數字的列表。

+0

哪條線給你的錯誤? – andrewsi

+0

$ sth->執行(陣列提供了錯誤。 – alias51

+0

您可能想要爲該INSERT語句添加一個VALUES子句。你只是假設它已經起作用了 - 你需要檢查返回值,並在失敗時做適當的處理。 – andrewsi

回答

1

貌似$pinarray是一個實例一個StdClass的。你可能打算搶available_pins場,是嗎?

$pinarray = $sth->fetch(); 
$this->user_pin = $pinarray->available_pins; 
+0

我認爲這是兩個摺疊,他試圖將一個值數組傳遞給execute語句,但是他們應該使用'bind_param()'no綁定。 – Ohgodwhy

+0

@Ohgodwhy我只是猜測在'$ sth'中正在使用的數據庫抽象層。有些使用問題中顯示的語法。 –

相關問題