简体   繁体   English

无法从PDO阵列提取数据

[英]Having trouble extracting data from PDO array

It might be the late hour or user error but I'm having trouble extracting variables from a PDO, where it would normally work. 可能是时间太晚或用户出错,但我无法从PDO提取变量,而PDO通常可以正常工作。 When I print_r my results by doing $array->results(), I get the following line: 当我通过执行$ array-> results()打印结果时,得到以下行:

Array ( [0] => stdClass Object ( [messageid] => 1 [fromid] => 2 [toid] => 1 [message] => Hello! ) ) 

However, on other projects when working with other people I have then just referred to the variable like this: 但是,在其他项目中,当与其他人一起工作时,我只是像这样引用变量:

$result['message']

This is obviously after the line 这显然是在行之后

$result = $array->results();

I've been troubleshooting and come to no conclusions, but I'm terrible at managing arrays so it could be something super simple. 我一直在进行故障排除,但没有得出任何结论,但是我在管理阵列方面非常糟糕,因此这可能非常简单。 Any ideas? 有任何想法吗? Thanks! 谢谢!

由于结果似乎是数组中的对象,因此获取数组并访问其中的对象,以从$result获取message对象,只需执行以下操作:

echo $result[0]->message;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM