PHP MySQL Fetch Data Example

PHP MySQL Fetch Data Example


Posted in : PHP Posted on : February 3, 2011 at 5:48 PM Comments : [ 0 ]

If you want to fetch records from the database then use SELECT statement. In this example, we have used existing database "php_mysql" and "user" database table for select record.

PHP MySQL Fetch Data Example:

If you want to fetch records from the database then use SELECT statement. In this example, we have used existing database "php_mysql" and "user" database table for select record.

Example:

<?php
$connection = mysql_connect("localhost", "root", "root");

if (!$connection) {
die('PHP Mysql database connection could not connect : ' . mysql_error());
}
else{ 
$db_name = "php_mysql";

mysql_select_db($db_name, $connection);
$sql = "select * from user;";
$records = mysql_query($sql, $connection); 
while($rows = mysql_fetch_array($records)){
echo "User Id : " . $rows['user_id'] . "<br />";
echo "User Name : " . $rows['user_name'] . "<br />";
echo "User Email : " . $rows['user_email'] . "<br />";
echo "User Address : " . $rows['user_address'] . "<br /><br /><br />";
}
}
mysql_close($connection); 
?> 

After running this example the output is:

output:

User Id : 1
User Name : brijesh
User Email : brijesh@gmail.com
User Address : Delhi

Download Example Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics