For debugging Database connection problems I use this script at the end of my ./config/database.php
...
...
...
echo '<pre>';
print_r($db['default']);
echo '</pre><p>‘;</p>
<p> echo ‘Trying to connect to database: ’ .$db[‘default’][‘database’];<br />
$dbh=mysql_connect<br />
(<br />
$db[‘default’][‘hostname’],<br />
$db[‘default’][‘username’],<br />
$db[‘default’][‘password’])<br />
or die(‘Cannot connect to the database because: ’ . mysql_error());<br />
mysql_select_db ($db[‘default’][‘database’]);</p>
<p> echo ‘<br />
Connected OK:’ ;<br />
die( ‘file: ’ .__FILE__ . ‘—> Line: ’ .__LINE__);
</pre>
BRILLIANT! I had the same problem connecting to my db - and it was not my first try with CI… But this one, I simply couldnt figure out why it couldnt connect.
With your debugscript, I noticed that I had mixed up the database name and password, and your script told me that it tried to connect to Database: mypassword.
Really good debug script, thank you very much 😊