Monday, 19 August 2013

Can't connect to localhost

Can't connect to localhost

I am learning PHP and am working on a script that connects to my DB and
pulls some data.
The website I have running on my localhost is a PHP driven CMS.
A segment of the script is here
DEFINE ('DB_USER','myname');
DEFINE ('DB_PASSWORD','somepass123');
DEFINE ('DB_HOST','localhost');
DEFINE ('DB_NAME','sitename');
// make the db connection
$dbc = @mysqli_connect('DB_HOST','DB_USER','DB_PASSWORD','DB_NAME')
OR die ('Could not connect to mysql: ' . mysqli_connect_error());
When I load a page that draws on the PHP I receive the following error
where the output data is meant to be:
Could not connect to mysql: Unknown MySQL server host 'DB_HOST' (1)
I did some research on SO and some googling around. A suspect issue could
be that DB_HOST is defined elsewhere. Is that plausible? I'm not
experienced enough to know if this is the right path.
I did find this in the config/database.php file, I'm not sure if it's
relevant:
$config['default'] = array(
'benchmark' => TRUE,
'persistent' => FALSE,
'connection' => array(
'type' => 'mysqli',
'user' => 'myname',
'pass' => 'somepass123',
'host' => 'localhost',
'port' => FALSE,
'socket' => FALSE,
'database' => 'sitename',
How would I approach figuring out next steps? Is this a common error? Does
anyone have any pointers?

No comments:

Post a Comment