我有一个简单的查询,从数字列表中选择一个 PIN,然后将该 PIN 分配给用户并将其插入到另一个表中:
$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));
但是,这会产生一个可捕获的 fatal error :类 stdClass 的对象无法转换为字符串,有什么想法吗?
其他信息
$sth->execute(array 给出错误,available_pins 使用mediumint(6)。它是随机 6 位数字的列表。
最佳答案
看起来$pinarray
是StdClass的一个实例。您可能打算获取 available_pins
字段,嗯?
$pinarray = $sth->fetch();
$this->user_pin = $pinarray->available_pins;
关于php - 可捕获的 fatal error : Object of class stdClass could not be converted to string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19325108/