Welcome Guest, Not a member yet? Register   Sign In
Database connection error


I'm trying to set up wamp at home, but getting this error message:
Quote:Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\websitename\system\database\DB_driver.php

Already checked config/database.php, a post elsewhere suggesting setting pconnect to false, so tried that too, but it didnt help. Also double-checked username/password details and db name, all correct (although not submitted here)
Other than host,user,pwd,db, and now pconnect, the rest are the default settings.

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'dbname';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$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;

Any suggestions please?
Any ideas gratefully received.

Thanks! Smile

Did you load the database?


Try this:

Save this code to ./application/config/database_DEBUG.php
// **********************************

    // cosmetic stuff
    if(! defined('jj'))
      define('jj', '<br />');
    echo '<b>Database configuration:</b>';
    echo '<pre>';
    echo '</pre>';

    echo    'Trying to connect: ';
    $dbh = mysql_connect
                die(jj .'Cannot connect to the database because: ' . mysql_error()
    $connected    = mysql_select_db ($db['default']['database']);
    $msg     = 'Big Problen cannot connect???'; // default
        $msg = 'Connected OK';
    echo jj, jj,  $msg;
    die(jj. jj.'<b>Debug:</b> file: ' .__FILE__ . '--&gt; Line: ' .__LINE__);

// ***********************************
Then include the file in your database.php

include 'database_DEBUG,php';

Thanks for this.
I still get an error, and can't explain it:
The output of the above is an error, it breaks at the mysql_connect:
Message: mysql_connect() [function.mysql-connect]: Access denied for user 'my_user'@'localhost' (using password: YES)
Filename: config/database_DEBUG.php
Line Number: 20
The access denied is a big clue, but the print_r displays the array being passed, and that includes the correct username and password for the database, so I can't see why its saying access denied.

Actually, I tried moving the line for mysql_select_db to be above the mysql_connect. That changed the error message to start mentioning the correct database name, but the username reported in the error was blank.
Moving it back again to where it is above, means that the error message doesn't mention the database name.

i.e. it becomes
Cannot connect to the database because: Access denied for user ''@'localhost' to database 'my_db'

OK, I think I'm back in business.
I changed the permissions for the user I created to apply to the Local host instead of to Any host.
That did the trick.

Thnks! I has this problem too...

when i access my main page i receive:
A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 232
i used the debugging code above and got:
    [hostname] => localhost
    [username] => dwerud4_ci
    [password] => 2q3JW^A}a2e9
    [database] => dwerud4_ci
    [dbdriver] => mysql
    [dbprefix] =>
    [pconnect] => 1
    [db_debug] => 1
    [cache_on] =>
    [cachedir] =>
    [char_set] => utf8
    [dbcollat] => utf8_general_ci
    [swap_pre] =>
    [autoinit] => 1
    [stricton] =>

Line: 111 : Connected OK
The problem is the host?

problem solved [db_debug] => must be false

In my Wamp it all worked perfectly. when uploaded to another server (which is running older versions of mysql and php btw) i first got the same error.
After some mods that led to nowhere, i just simply left the username and password blank, and then it connected perfectly.
no other mods were necessary or debug code proved helpful.

Theme © iAndrew 2016 - Forum software by © MyBB