Select data from mysql database with PHP



User Rating:  / 0
PoorBest 
Details
Category: php
Created on Tuesday, 08 May 2012 09:18
Last Updated on Tuesday, 22 May 2012 10:53
Published on Tuesday, 08 May 2012 09:18
Written by Administrator
Hits: 5674

How to select data from mysql database with php :

1. Make connection to mysql

2. Execute query

3. Write results to page 

Example : 

View source
 
<?php
 
 
// www.developerpages.gr
 
 
$con = mysql_connect("localhost","root","12345");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("test_db"$con);
 
$result = mysql_query("SELECT * from example_table");
 
 
echo " border='1'>
 
 
<tr>
<th>id</th>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
 
while($row = mysql_fetch_array($result))
  {
  echo "";
  echo "" . $row['id'] . "";
  echo "" . $row['FirstName'] . "";
  echo "" . $row['LastName'] . "";
  echo "";
  }
 
mysql_close($con);
?>

and the output is :