Connecting to a MySQL Database on Your Linux Hosting Account Using PHP

Below is a code sample for connecting to a MySQL database using PHP.
<?php
//Sample Database Connection Syntax for PHP and MySQL.

//Connect To Database
$hostname="mysql.secureserver.net";
$username="your_dbusername";
$password="your_dbpassword";
$dbname="your_dbusername";
$usertable="your_tablename";
$yourfield = "your_field";
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);

# Check If Record Exists

$query = "SELECT * FROM $usertable";

$result = mysql_query($query);

if($result)
{
while($row = mysql_fetch_array($result))
{
$name = $row["$yourfield"];
echo "Name: ".$name."
";
}
}
?>

Article Details

Article ID:
23
Category:
Date added:
06-26-2011 19:47:02
Views:
682
Rating (Votes):
(326)