- Open a new file in your text editor
- Paste in the following code:
<?php
$dbhost = 'localhost';
$dbuser = '[DATABASE USERNAME]';
$dbpass = '[DATABASE PASSWORD]';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = '[DATABASE NAME]';
mysql_select_db($dbname);
?>
Replace [DATABASE USERNAME] with the name of your database user. Replace [DATABASE PASSWORD] with the password for your database user. Replace [DATABASE NAME] with the name of your database.
- Save this file as [NAME].php and upload it to your account.
When you want to access the database in any PHP script:
- Add the following line to your script:
include '[NAME].php'
- The database can now be queried, using standard SQL commands, and the following line:
mysql_query('QUERY')