我有選擇從號碼列表一個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位數字的列表。
哪條線給你的錯誤? – andrewsi
$ sth->執行(陣列提供了錯誤。 – alias51
您可能想要爲該INSERT語句添加一個VALUES子句。你只是假設它已經起作用了 - 你需要檢查返回值,並在失敗時做適當的處理。 – andrewsi