Share on Google+Share on Google+

PDO Fetch Num

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

PDO Fetch Num:

We've discussed in the previous tutorial about PDO::FETCH_ASSOC, similarly PDO provides another function which returns the numerical index of the result unlike the PDO::FETCH_ASSOC which returns the name of the field. To make the differences clear please compare the previous result and the result given below, you'll find that the result of the  current tutorial is in numeric form.








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

$sql="select * from student";



echo "<table border=1>";

foreach($result as $key=>$val){

echo "<tr><td>".$key."</td>";

echo "<td>".$val."</td></tr>";}

echo "</table>";


catch(PDOException $c){

echo $c->getMessage(); }





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.