One of the best advantages of PHP is that, it can integrate with Mysql Databases and output those database records in your browser. Here's the basic script on how to connect to the Mysql Database.
//First you need to have a mysql username and password as the security access for your mysql database.
$username_conn = "dbuser"; //the mysql user with database rights
$password_conn = "dbpassword"; //the security mysql password
$hostname_conn = "localhost"; //the default is usually localhost
$database_conn = "task_db"; //the name of the database
//the script to connect to the database
$conn = mysql_connect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
//select the database to work with
mysql_select_db($database_conn, $conn);
$query_rstTask = sprintf("SELECT taskid,taskname,assignedto FROM tbl_task");
//execute the SQL query and return records
$rstTask = mysql_query($query_rstTask, $conn) or die(mysql_error());
//fetch tha data from the database
while ($row = mysql_fetch_array($rstTask)) {
//Display the results
echo "Task ID:".$row{'taskid'}." Task Name:".$row{'taskname'}." Assigned To: ".$row{'assignedto'}."
";
}
//close the connection
mysql_close($conn);
?>
Tuesday, January 20, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment