CodeIgniter Forums
Problems with database connection - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Problems with database connection (/showthread.php?tid=71608)



Problems with database connection - renanrfranca - 09-04-2018

Whenever I try to load the sessions library in my controller I get an error message on my page:

Message: mysqli::real_connect(): (HY000/1045): Access denied for user ''@'(my external ip)' (using password: NO)

I think my database.php file is properly configured. x.x.x.x is the ip of a remote database I can connect to through DBeaver. Either way it seems the connection is completely ignoring my configurations.

I should probably add that I'm using docker-compose with this image, but I don't think it's related.

PHP Code:
$db['default'] = array(
    
'dsn'    => '',
    
'hostname' => 'x.x.x.x',
    
'database_user' => 'username',
    
'database_password' => 'password',
    
'databasename' => 'name',
    
'dbdriver' => 'mysqli',
    
'dbprefix' => '',
    
'pconnect' => FALSE,
    
'db_debug' => (ENVIRONMENT !== 'production'),
    
'cache_on' => FALSE,
    
'cachedir' => '',
    
'char_set' => 'utf8',
    
'dbcollat' => 'utf8_general_ci',
    
'swap_pre' => '',
    
'encrypt' => FALSE,
    
'compress' => FALSE,
    
'stricton' => FALSE,
    
'failover' => array(),
    
'save_queries' => TRUE
); 



RE: Problems with database connection - Pertti - 09-04-2018

https://www.codeigniter.com/user_guide/database/configuration.html?highlight=database

In your array you have database_username where it should be just username.

Are you using CI3? (Too lazy to check if CI4 uses different array key names Tongue )


RE: Problems with database connection - renanrfranca - 09-04-2018

(09-04-2018, 07:34 AM)Pertti Wrote: https://www.codeigniter.com/user_guide/database/configuration.html?highlight=database

In your array you have database_username where it should be just username.

Are you using CI3? (Too lazy to check if CI4 uses different array key names Tongue )

Hmm, very odd. I'm using CI 3.1.9 and I don't recall messing with this file, but as a beginner I suppose I must have done something very wrong at some point. Thank you, I've been dealing with this for longer than I'd like to admit.

Edit: Yeah, solved it.


RE: Problems with database connection - Pertti - 09-04-2018

Hey it's most of the time something glaring obvious right in front of you, but you just can't see it in your own code.

Glad it worked Smile