Retrieving data from database is as easy using php. I am using mysql as my database server.
<?php
$host = "localhost"; //your local computer
$username = "root"; // your database server's username
$password = "yoursecretpassword"; //you can encrypt this password, if you need not to see by others
$database = "test"; //test is my database
$conn = mysql_connect($host,$username,$password) or die("<b>Error in connection:</b>".mysql_error());
mysql_select_db($database,$conn);
$sql = mysql_query("select * from users",$conn) or die("<b>Error in Query:</b>".mysql_error($conn));
$affected_rows = mysql_num_rows($sql);
if($affected_rows>0)
{
while($rs = mysql_fetch_array($sql))
{
echo "Hi ". $rs['name'].",<br />";
echo "Your age is ".$rs['age']."...<br /><br />";
}
}
?>
In the above example, I considered that you have table name called users and you have field names name,age in the users table.
If you have any questions in this script or need new script, feel free to post your questions here.
No comments:
Post a Comment