CodeIgniter Forums
[SOLVED] Database Connection Issue - - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: [SOLVED] Database Connection Issue - (/thread-43622.html)



[SOLVED] Database Connection Issue - - El Forum - 07-18-2011

[eluser]Unknown[/eluser]
This is such a newbie issue, but I'm having trouble connecting to my database. I know the information within my database.php file is correct. CI requires you to test out the connection when you install it and I haven't touched the file since. I've tried using autoload.php and manually connecting to the database with long & shorthand. I've quadrupled check the info in my cPanel. I don't get it...

Is there anything else (aside from wrong info in db.php) that could cause the database not to connect? I've copied in what my loader.php file looks like. Is this normal? Assuming it is, just trying to troubleshoot.

Also, my database.php is in my application config and my loader.php is in my system core. I renamed the application/system file folders of course....not sure if I should be updating any filepaths in one of these files. Any ideas of what could be going on?

Thanks in advance!

Code:
function database($params = '', $return = FALSE, $active_record = NULL)
    {
        // Grab the super object
        $CI =& get_instance();

        // Do we even need to load the database class?
        if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
        {
            return FALSE;
        }

        require_once(BASEPATH.'database/DB'.EXT);

        if ($return === TRUE)
        {
            return DB($params, $active_record);
        }

        // Initialize the db variable.  Needed to prevent
        // reference errors with some configurations
        $CI->db = '';

        // Load the DB class
        $CI->db =& DB($params, $active_record);
    }



[SOLVED] Database Connection Issue - - El Forum - 07-18-2011

[eluser]jmadsen[/eluser]
A bit confused by your post.

first, CI does NOT require you to test out the connection when you install, so not sure what you did.

also, what message(s) are you getting? a generic "could not connect to database", or something else?

try this code in your controller, and see if you have basic info you need, and db permissions:

Code:
<?php
$con = mysql_connect($host,$username,$password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code
?>