GoDaddy Support

MySQL Connection String with PHP

Date Submitted: 9/7/14

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):

<?php //Sample Database Connection Syntax for PHP and MySQL. //Connect To Database $hostname=""; $username="your_dbusername"; $password="your_dbpassword"; $dbname="your_dbusername"; $usertable="your_tablename"; $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>"); mysql_select_db($dbname); # 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."<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

About GoDaddy


United States - English
Traffic Log Image