Connect to MySQL database

Submitted by:David Villa

Date added:18 June, 2013


Define few variables with your MySQL database connection settings and connect to MySQL database using mysql_connect() and mysql_select_db() functions.

Tags: connect to database

Code Snippet:


// set your MySQL login details
$db_host = "localhost";
$db_user = "username";
$db_pass = "password";
$db_name = "databasename";

$connection = mysql_connect($db_host,$db_user,$db_pass);
if (!(mysql_select_db($db_name,$connection))) {
echo "Could not connect to the database";