Share on Google+Share on Google+

PDO Fetch Lazy

Ads
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
)

Advertisements

Posted on: April 5, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Ads

Advertisement