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';

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.

Was this answer helpful?

 Print this Article

Also Read

I am having problems uploading via the File Manager.

The File Manager makes use of Adobe Flash technology, and requires Flash Player 10 for full...

How can I manage my MySQL database?

Once you have created a database using your Online Control Panel Control Panel you will be able...

I've uploaded files to File manager but cannot see them, they were recently visible. What's happened?

File manager has a 5mb memory limit which restricts the number of files that can be displayed if...

How do I create a MySQL database?

If your account type includes MySQL databases, then log in to your Online Control Panel Control...

How do I create a mail box?

Creating mail boxes inside Online Control Panel is nice and easy, and can be done in just 3...