How to fetch records (rows) form a table into a list() variables with PDO in PHP

1 Answer

0 votes
$con = new PDO("mysql:host=".$db_host.";dbname=".$db_name, $db_user, $db_password);
$result = $con->query("SELECT image_id, href, src FROM images");
while (list($image_id, $href, $src) = $result->fetch(PDO::FETCH_NUM)) 
{
    echo "$image_id : $href : $src" . "<br />";
}


/*
run: 

49 : https://www.ws.com : http://www.ws.com/images/us-flag.gif
50 : https://www.ws.com : http://www.ws.com/images/logo.png
51 : https://www.ws.com : http://www.ws.com/images/discount.png

*/

 



answered Jul 3, 2016 by avibootz
...