问题描述
我有一个包含 'operation.date'、'operation.name' 等列的 mysql 表.使用 $mysqli->fetch_object()
将该表数据作为对象获取后,我得到了这个(行的 print_r):
I have mysql table with collumns like 'operation.date', 'operation.name' and etc.After fetching that table data as object with $mysqli->fetch_object()
i get this (print_r of row):
stdClass Object
(
[id] => 2
[operation.date] => 2010-12-15
[operation.name] => some_name
)
我如何访问 operation.date
和 operation.name
以及所有其他奇怪命名的对象属性?
how do I acces operation.date
and operation.name
and all other weirdly named object properties?
推荐答案
在 SQL 查询中指定别名,例如 SELECT column AS nameWithoutDots ...
或使用 $object->{'operation.name'}
访问这些属性或者像这样将对象转换为数组: $obj = (array)$obj;echo $obj['operation.name']
.
Specify aliases in your SQL query like SELECT column AS nameWithoutDots ...
or access these properties with $object->{'operation.name'}
or cast the object to array like this: $obj = (array)$obj; echo $obj['operation.name']
.
这篇关于名称中带点的php对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!