I was working with PDO, and could not understand PDO::FETCH_LAZY. In PHP manual it says "...PDO::FETCH_LAZY creates the object variable names as they are accessed...". I have this code to test this:
class b{ function __construct(){} } $b = new b(); $pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'pssword'); //testtable{id int, title varchar, msg varchar, time varchar} $res = $pdo->query("SELECT * FROM testtable limit 1"); $b = $res->fetch(PDO::FETCH_LAZY); echo $b->msg; var_dump($b);
This is supposed to print the object b with only 1 property, msg. But instead, the output is this:
This is a sample message. object(PDORow)#6 (5) { ["queryString"]=> string(31) "SELECT * FROM testtable limit 1" ["id"]=> string(1) "1" ["title"]=> string(5) "sample title" ["msg"]=> string(13) "This is a sample message." ["time"]=> string(7) "1232123" }
Can anyone please throw some light on this? Thanks.
var_dump($b)
would cause it to access all the properties and load them. - Cfreak