• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database connection error

#1
[eluser]igniterman[/eluser]
Hi,

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.

Code:
$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

#2
[eluser]InsiteFX[/eluser]
Did you load the database?

InsiteFX

#3
[eluser]John_Betong_002[/eluser]
Try this:

Save this code to ./application/config/database_DEBUG.php
Code:
<?php
// **********************************

    // cosmetic stuff
    if(! defined('jj'))
    {
      define('jj', '<br />');
    }
    
    echo '<b>Database configuration:</b>';
    echo '<pre>';
      print_r($db['default']);
    echo '</pre>';

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

// ***********************************
&nbsp;
Then include the file in your database.php
&nbsp;

./application/config/database.php
Code:
...
...
...
include 'database_DEBUG,php';
&nbsp;
&nbsp;

#4
[eluser]igniterman[/eluser]
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:
Code:
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
Code:
Cannot connect to the database because: Access denied for user ''@'localhost' to database 'my_db'

#5
[eluser]igniterman[/eluser]
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.
Thanks!

#6
[eluser]Unknown[/eluser]
Thnks! I has this problem too...

#7
[eluser]dsp77[/eluser]
when i access my main page i receive:
Code:
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:
Code:
Array
(
    [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
Success
The problem is the host?

#8
[eluser]dsp77[/eluser]
problem solved [db_debug] => must be false

#9
[eluser]Unknown[/eluser]
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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.