Using PDO::FETCH_CLASS with Magic Methods

和自甴很熟 提交于 2019-11-29 04:06:48

The default behavior of PDO is to set the properties before invoking the constructor. Include PDO::FETCH_PROPS_LATE in the bitmask when you set the fetch mode to set the properties after invoking the constructor, which will cause the __set magic method to be called on undefined properties.

$st->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Foo');

Alternatively, create an instance and fetch into it (i.e. set fetch mode to PDO::FETCH_INTO).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!