PHP PDO :: FETCH_LAZY - does not create object variable names when they are accessed

I worked with PDO and could not understand PDO :: FETCH_LAZY. The PHP manual says: "... PDO :: FETCH_LAZY creates the names of object variables when they are accessed ...". I have this code to check 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);

It is supposed to print object b with only 1 property, msg. But instead, the conclusion is as follows:

  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 shed some light on this? Thanks.

+2
source share
1 answer

in line

$b = $res->fetch(PDO::FETCH_LAZY); 

you pointed a new value (PDORow object) to the variable $ b overwriting object "b"

+1
source

All Articles