Mysql Database Connect
By Brian on Feb 14, 2009 with Comments 1
To connect to a Mysql database you need a few things first.
Of course you need to have the database created with a name you make up as well as the username and password of the mysql account that can connect to that database. This is very simple if you are using web managing software such as Cpanel or DirectAdmin. Under the Mysql databases area you can do all of this quickly.
For many websites mysql connections are included in a common file such as “config.php”. Here is how a basic mysql connection looks:
$host = "localhost"; $db_username = "USERNAME"; $db_password = "PASSWORD"; $db_name = "DATABASE"; mysql_connect($host,$db_username,$db_password) or die(mysql_error());
$host – The host that you are connecting to. Usually set to “localhost”.
$db_username – The username of the account that connects to the database specified.
$db_password – The password of the account that connects to the database specified.
$db_name – The name of the database you are connecting to. This is shown in your domain managing area.
This code will connect to a mysql database and if there are any errors reported it will end php and display the errors.
Popularity: 1% [?]
Filed Under: Scripts • Tutorials • Web Programming

[...] Before we can grab anything from a mysql database we have to connect to it. Find how to connect to a mysql database here. [...]