Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I'm having trouble making a connection to Amazons RDS service from my Codeigniter application.

Settings in database config: 

$db['default']['ssl_set'] = TRUE;

$db['default']['ssl_key'] = NULL;

$db['default']['ssl_cert'] = NULL;

$db['default']['ssl_ca'] = realpath('./application/third_party/mysql-ssl-ca-cert.pem');

$db['default']['ssl_capath'] = NULL;

$db['default']['ssl_cipher'] = NULL;

However, when I connect. I get the message:

 

Unable to select the specified database: Staging Filename: ...\system\database\DB_driver.php Line Number: 140

Line 40 is shown here: 

    // Select the DB... assuming a database name is specified in the config file

    if ($this->database != '')

    {

        if ( ! $this->db_select())

        {

            log_message('error', 'Unable to select database: '.$this->database);

 

            if ($this->db_debug)

            {

                $this->display_error('db_unable_to_select', $this->database); // LINE 140

            }

            return FALSE;

        }

I made the following changes to get mysqli working with SSL: 

I'm surprised it connected successfully as its complaining about database selection. Not sure where to go from here though? 

I'm using PHP 5.3.8 on a windows machine. 

This is turning more into a bug than a problem with my implementation. If I set the $db['default']['db_debug'] to false. I don't get that problem anymore. However, I get a bunch of warnings to do with: 

Severity: Warning

Message: mysqli_real_escape_string() [function.mysqli-real-escape-string]: invalid object or resource mysqli

Filename: mysqli/mysqli_driver.php

Line Number: 346

Which means there was an unsuccessful connection to the database over SSL. 

I am using XAMPP. 

And I am using Codeigniter 2.0.2. 

My database config file: 

$db['default']['hostname'] = 'xxxx.us-east-1.rds.amazonaws.com';

$db['default']['username'] = 'xxxxx';

$db['default']['password'] = 'xxxx';

$db['default']['database'] = 'xxxx';

$db['default']['dbdriver'] = 'mysqli';

$db['default']['port'] = 3306;

$db['default']['dbprefix'] = '';

$db['default']['pconnect'] = TRUE;

$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;

$db['default']['ssl_set'] = true; 

$db['default']['ssl_key'] = NULL;

$db['default']['ssl_cert'] = NULL;

$db['default']['ssl_ca'] = realpath('./application/third_party/mysql-ssl-ca-cert.pem');

$db['default']['ssl_capath'] = NULL;

$db['default']['ssl_cipher'] = NULL;

1 Answer

0 votes
by (44.4k points)

Add this to the database config. mysql_real_connect() needs param 6 to be a LONG integer:

$db['default']['port'] = 3306;

In DB_Driver, below line 140 where dbcollat and charset are set, so these will hit real_escape in the driver and if there is an error, it will cause an escape_error.

Try this:

$db['default']['dbcollat']='';

Related questions

0 votes
1 answer
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
2 answers
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...