user1592380
user1592380

Reputation: 36227

xampp error: does not connect to database server , with codeigniter

I am working on a codeigniter project. I developed it using wampserver locally, but I'd like to make some changes with xampp . It works fine on the remote site. Unfortunately when I try to run it locally I am getting:

A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: F:\xampp-portable\htdocs\....\database\DB_driver.php
Line Number: 124

to my index.php file , I have added:

mysql_connect("localhost","root","") or die ("Could not connect to mysql server.");
mysql_select_db("contacts_db") or die ("Could not connect to database.");

This does NOT generate an error. Can anyone give me some pointers on what to check next?

Thanks in advance,

Bill

OK guys, here is the code around line 124:

function initialize()
{
    // If an existing connection resource is available
    // there is no need to connect and select the database
    if (is_resource($this->conn_id) OR is_object($this->conn_id))
    {
        return TRUE;
    }

    // ----------------------------------------------------------------

    // Connect to the database and set the connection ID
    $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this-        >db_pconnect();

    // No connection resource?  Throw an error
    if ( ! $this->conn_id)
    {
        log_message('error', 'Unable to connect to the database'); // 124

        if ($this->db_debug)
        {
            $this->display_error('db_unable_to_connect');
        }
        return FALSE;
    }

John was right, although I am now confused. I had set up the following code in my index.php to auto switch between xampp and server database config files:

define('ENVIRONMENT', isset($_SERVER['SERVER_NAME'])=='my_domain_name.com' ? 'production' : 'development');

    echo 'SERVER_NAME  '.$_SERVER['SERVER_NAME']; // getting localhost
    echo 'env '.ENVIRONMENT; // getting production.

I thought this would result in the ENVIRONMENT constant set to 'development' with $_SERVER['SERVER_NAME']=localhost. Would someone mind explaining what I'm doing wrong here?

Upvotes: 0

Views: 10459

Answers (1)

SubRed
SubRed

Reputation: 3187

Please check your config/database.php file, as I know the config database in codeigniter is in this file. Some values you need to pay attention are:

$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';

Upvotes: 3

Related Questions