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'm trying to upload a large file onto my webspace, and the file manager inside the Online Control Panel Control Panel won't let me. Why?

This is due to the nature of the web based FTP used, and your browser/ISP connection timing out...

On accessing the control panel, the error "for security reasons your session has expired" is displayed?

There are a few reasons why the session expiry error is displayed when accessing the Online...

File Manager session expiry errors

In order to keep your files secure against various threats, File Manager requires that your...

Why am I getting a 550 error when trying to create folders in file manager?

This suggests a permissions problem related to the creation of the account. You should contact...

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...