PHP MySql Select Tutorial
In this PHP MySQL tutorial, we will select users table from MySQL Server using PHP code sample below.
PHP SQL Select Code
<?php
$con = mysql_connect("localhost","UserName","UserPassword");
if (!$con)
{
die('Error on connecting: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM tbl_users");
while($row = mysql_fetch_array($result))
{
echo $row['Name'] . " - " . $row['Email'] ."<br />";
}
mysql_close($con);
?>
It is always better to put this kind of functions seperate of your main page code, call it function.php, and you may include into your main php pages.