So this is a pretty weird error.
This is how my application/config/database.php
file is formatted:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'db_name';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
/* End of file database.php */
/* Location: ./application/config/database.php */
$mysqli=mysqli_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'],
$db['default']['database']
);
echo (mysqli_connect_errno()) ? "Failed to connect to MySQL: " . mysqli_connect_error() : "Connected OK";
die( "\n<br>Filename: " .__FILE__ . "\n<br>Line number: " .__LINE__);
I get this error when I load the site:
Failed to connect to MySQL: Can't connect to MySQL server on '127.0.0.1' (13)
Filename: /var/www/html/application/config/database.php
Line number: 86
Now, here's the weird part. I made a new file in that folder, with the following code:
<?
define('BASEPATH', 'active');
require_once "database.php";
The response when I run php test.php
from command line?
<pre>Array
(
[hostname] => 127.0.0.1
[username] => root
[password] =>
[database] => db_name
[dbdriver] => mysql
[dbprefix] =>
[pconnect] =>
[db_debug] =>
[cache_on] =>
[cachedir] =>
[char_set] => utf8
[dbcollat] => utf8_general_ci
[swap_pre] =>
[autoinit] => 1
[stricton] =>
)
</pre>Connected OK
<br>Filename: /var/www/html/application/config/database.php
<br>Line number: 83
Why does test.php
work from command line but trying the main site fail? Please help, I'm at a loss here.