PDO Fetch Lazy


 

PDO Fetch Lazy

In this tutorial we will study about PDO Fetch Lazy method in PHP, how to access MySQL using PDO Fetch Lazy method , How to retrieve data etc. Examples will make this clearer.

In this tutorial we will study about PDO Fetch Lazy method in PHP, how to access MySQL using PDO Fetch Lazy method , How to retrieve data etc. Examples will make this clearer.

PDO Fetch Lazy:

PDO::FETCH_LAZY is the combination of PDO::FETCH_OBJ and PDO::FETCH_BOTH. It displays the query which has been made along with the object variable names as they are accessed. Following  example illustrates the idea, and as you see the output, you will find the it displays the query and the field names and their respective values.

Example:

<?php

header('Content-type:text/plain');

$host='localhost';

$user='root';

$password='';

try

{

$dbh=new PDO("mysql:host=$hostname;dbname=ajax",$user,$password);

$sql="select * from student";

$stmt=$dbh->query($sql);

$obj=$stmt->fetch(PDO::FETCH_LAZY);

print_r($obj);

$dbh=null;

}

catch(PDOException $c)

{

echo $c->getMessage();

}

?>

 

Output:

PDORow Object
(
    [queryString] => select * from student
    [name] => neeraj
    [roll] => 2
)

Ads