Select data from mysql database with PHP
Details
- 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: 8420
How to select data from mysql database with php :
1. Make connection to mysql
2. Execute query
3. Write results to page
Example :
<?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 :