Simplest php program to fetch from mysql and print



<?php
$host = "localhost";
$user = "root";
$pass = "password"; //db password here
$dbName = "sample";// database name
$db = mysql_connect($host,$user,$pass) or die(mysql_error());
if ($db) {
echo 'Connected successfully<br />';
}
mysql_select_db($dbName);
$q = "select name,age from users order by id desc limit 10";
$res = mysql_query($q);

while ($row = mysql_fetch_assoc($res)) {
echo $row["id"] . "   " . $row["name"] . "   " . $row["age"] . "<br />";
}
?>

One thought on “Simplest php program to fetch from mysql and print

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s