GoDaddy Support

MySQL Connection String with PHP

Date Submitted: 6-27-2011

To connect to your MySQL database using PHP you will need a connection string. This is a PHP MySQL Connection Example (PHP is available on Linux hosting accounts and Windows hosting accounts using IIS 7 only):

//Sample Database Connection Syntax for PHP and MySQL.

//Connect To Database

$yourfield = "your_field";

mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");

# Check If Record Exists

$query = "SELECT * FROM $usertable";

$result = mysql_query($query);

while($row = mysql_fetch_array($result))
$name = $row["$yourfield"];
echo "Name: ".$name."<br>";

For more information, see the MySQL Functions page at

Rate This Article:

NEED HELP? Call our award-winning support team 24/7 at (480) 505-8877

United States - English
Traffic Log Image