php - 可捕获的 fatal error : Object of class stdClass could not be converted to string

标签 php mysql sql

我有一个简单的查询,从数字列表中选择一个 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/

相关文章:

mysql - 使用 mysql 处理非常大的数据

PHP:活跃用户

php - header() 重定向后如何使用变量?

java - 选择图片并上传到服务器

mysql - 从两个表中获取数据

mysql - 列出受相同抗生素影响的细菌对

java - 如何在 IBatis 2 中使用 SQL Like 运算符?

sql - SQLite 可以处理 9000 万条记录吗?

sql - 如何搜索例程的内容/(SP-触发函数)

php - 克隆、模糊、裁剪和合成 Gif 动画