CodeIgniter Forums
problem cconnecting MYSQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: problem cconnecting MYSQL (/showthread.php?tid=67529)



problem cconnecting MYSQL - Gustavo Woltmann - 03-06-2017

I'm having problems getting CodeIgniter to connect to a remote DB.

My base system is as follows:
CentOS 7 running on AWS
Apache, PHP and MySQL Client Installed
Installed php-mysql
CodeIgniter 3.0.0 installed and working with pages not using DB.

Remote database:
Amazon RDS running MySQL (separate machine).

I can connect to the DB from the base system using MySQL command line.
When I try connecting to the DB through a CodeIgniter connector, I receive the error below.
I'm using the same parameters in database.php in CI as in MySQL command line (checked a few times)

Any ideas? Thanks.

Andy

Severity: Warning
Message: mysqli::real_connect(): (HY000/2003): Can't connect to MySQL server on 'hostname' (13)
Filename: mysqli/mysqli_driver.php
Line Number: 135
Backtrace:
File: /var/www/html/application/controllers/Messages.php
Line: 72
Function: database
File: /var/www/html/index.php
Line: 292
Function: require_once

$db['default'] = array(
'dsn' => '',
'hostname' => 'hostname',
'username' => 'user',
'password' => 'pwd',
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'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: problem cconnecting MYSQL - marksman - 03-06-2017

You will have to change hostname into your mysql server ip address

e.g
PHP Code:
$db['default'] = array(
    
'dsn' => '',
    
'hostname' => '127.255.255.255',
    
'username' => 'user',
    
'password' => 'pwd',
    
'database' => 'YOURDATABASENAME',
    
'dbdriver' => 'mysqli',
    
'dbprefix' => '',
    
'pconnect' => FALSE,
    
'db_debug' => TRUE,
    
'cache_on' => FALSE,
    
'cachedir' => '',
    
'char_set' => 'utf8',
    
'dbcollat' => 'utf8_general_ci',
    
'swap_pre' => '',
    
'encrypt' => FALSE,
    
'compress' => FALSE,
    
'stricton' => FALSE,
    
'failover' => array(),
    
'save_queries' => TRUE
);