Αναζήτηση

Saturday, May 12, 2012

Select data from mysql database with PHP

How to select data from mysql database with php :
1. Make connection to mysql
2. Execute query
3. Write results to page
Example :

<?php
$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 "<table 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 :

Original Article : http://developerpages.gr/index.php/el/web-development-2/php/64-select-data-from-mysql-database-with-php

No comments:

Post a Comment