How do I connect to my MySQL database?

A simple php script to open a connection to a database

$dbhost = 'localhost';
$dbuser = 'db username';
$dbpass = 'db password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'db name';
mysql_select_db($dbname);
?>

Save this as .php and then whenever you want to access the database, just add

include '.php'

to the top of a php script and the database can be queried using standard sql commands.

  • 67 Users Found This Useful
Was this answer helpful?

Related Articles

How do I backup my MySQL database?

Backing up your MySQL database can be done in several ways1. Using the backup tool from the Web...

How can I manage my MySQL database?

Once you have created a database using your Fast Name Control Panel you will be able to manage it...

How can I upload my MySQL database?

There are numerous ways to upload a MySQL database, we would strongly recommend trying methods 2...

Powered by WHMCompleteSolution