我正在尝试从下面的对象引用COUNT(*)
。我按照下面的示例使用 $the_date = $obj2->the_date
获取日期,但如何引用 count
?当然,使用 COUNT(*)
会抛出错误。
object(stdClass)[358]
public 'COUNT(*)' => string '36' (length=2)
public 'the_date' => string '2019-08-29' (length=10)
最佳答案
您需要为查询结果集中的相关列设置别名,例如:
SELECT the_date, COUNT(*) as cnt FROM ...
然后:
object(stdClass)[358]
public 'cnt' => string '36' (length=2)
public 'the_date' => string '2019-08-29' (length=10)
关于php - 引用 PHP 对象中的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57948324/