doxd96148 2012-03-01 20:51
浏览 90

Codeigniter:连接到SSL Amazon RDS数据库

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 suprised 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 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.

Update 2

I am using XAMPP.

And I am using Codeingiter 2.0.2.

Update 3

My database config file:

$db['default']['hostname'] = '';
$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条回答 默认 最新

  • duandingqi9442 2012-03-07 16:32
    $db['default']['port'] = 3306;

    Try adding that to db config. mysql_real_connect() expects param 6 to be a LONG int; balks at empty string.


    The function below line 140 in DB_Driver is where the dbcollat and charset are set. Those will hit real_escape in the driver, and cause the escape_error if not correct.



    Or, check that the encoding your db is set for what you have in your db config. i.e. if your db charset is latin1 and you are using utf-8, the conn_id will be wrong and mysqli_escape will balk.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 Python ModuleNotFoundError报错,如何解决?
  • ¥15 我下载图形界面重启完就变成这样了,打字也打不了,动也动不了,该怎么解决(操作系统-centos)
  • ¥15 VBA中在窗体中遍历所有checkbox控件,提取出被选中的checkbox的caption值
  • ¥15 在Ubuntu上有什么命令,或者是系统文件能告诉我链接nvme ssd的pcie槽位是不是支持热插拔功能?
  • ¥15 ansys license许可证问题
  • ¥20 QQ号和密码都能正常登录微信 QQ号和密码登录微信显示密码错误
  • ¥15 qiankun主应用注册子应用提示跨域
  • ¥15 单片机RTOS Kernel与应用分离开发,Kernel如何调起应用?
  • ¥15 快手小店商家版APP怎么第三方APP跳转到指定用户聊天界面
  • ¥15 为什么AVL fire软件仿真时的步长改变了,仿真结果也会改变