<?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.
When you want to access the database in any PHP script:
include '[NAME].php'
mysql_query('QUERY')
Article ID: 9
Created On: Thu, Feb 26, 2015 at 4:53 PM
Last Updated On: Wed, Apr 29, 2015 at 9:10 AM
Online URL: https://www.heartinternet.uk/support/article/how-do-i-connect-to-my-mysql-database-using-php.html