我正在使用 PDO,并且无法理解 PDO::FETCH_LAZY。在 PHP 手册中,它说“...PDO::FETCH_LAZY 在访问对象变量名称时创建它们...”。我有这个代码来测试这个:
b 类{
函数 __construct(){}
}
$b = 新 b();
$pdo = new PDO('mysql:host=localhost;dbname=test', '用户名', 'pssword');
//testtable{id int, title varchar, msg varchar, time varchar}
$res = $pdo->query("SELECT * FROM testtable limit 1");
$b = $res->fetch(PDO::FETCH_LAZY);
回声 $b->msg;
var_dump($b);
这应该打印只有 1 个属性 msg 的对象 b。但相反,输出是这样的:
这是一条示例消息。
对象(PDORow)#6 (5) {
[“查询字符串”]=>
string(31)“从测试表限制 1 中选择 *”
[“id”]=>
字符串(1)“1”
[“标题”]=>
string(5) “示例标题”
[“消息”]=>
string(13)“这是一条示例消息。”
[“时间”]=>
字符串(7)“1232123”
}
有人能解释一下吗?谢谢。