CodeIgniter Forums
Can't connect to MySQL (Azure) using SSL encrypt connection - 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: Can't connect to MySQL (Azure) using SSL encrypt connection (/showthread.php?tid=79089)



Can't connect to MySQL (Azure) using SSL encrypt connection - luizzz - 04-18-2021

Well, i do a connection successfully, in the same server, when using mysqli_real_connect as we can see below:

PHP Code:
$host 'myhost.mysql.database.azure.com';
$username 'user';
$password 'pass';
$db_name 'foo';
$conn mysqli_init();
if(!
$conn) {
 die(
'No init');
}

mysqli_real_connect($conn$host$username$password$db_name3306NULLMYSQLI_CLIENT_SSL);

if (
mysqli_connect_errno($conn))
{
    die('Failed to connect to MySQL: '.mysqli_connect_error());
}
else
{
 die(
'Good to go');


But on CodeIgniter 4, gives me an Unable to connect to the database exception with this similar settings:

PHP Code:
public $default = [
 
'DSN'      => '',
 
'hostname' => 'myhost.mysql.database.azure.com',
 
'username' => 'user',
 
'password' => 'pass',
 
'database' => 'foo',
 
'DBDriver' => 'MySQLi',
 
'DBPrefix' => '',
 
'pConnect' => false,
 
'DBDebug'  => (ENVIRONMENT !== 'production'),
 
'charset'  => 'utf8mb4',
 
'DBCollat' => 'utf8mb4_unicode_ci',
 
'swapPre'  => '',
 
'encrypt' => array(
            'ssl_ca' => '',
            'ssl_verify' => false),
 
'compress' => false,
 
'strictOn' => false,
 
'failover' => [],
 
'port'    => 3306
]; 

What can i do?

Alredy did:
- ssl_verify to true
- ssl_ca pointing to a ca_cert, as shown in: https://docs.microsoft.com/en-us/azure/mysql/connect-php


RE: Can't connect to MySQL (Azure) using SSL encrypt connection - luizzz - 04-24-2021

Solved.
i've changed by myself the file /system/Database/MySQLi/Connection.php

From:
[Image: aVkQJ6J.png]

To:
[Image: G6745wQ.png]

Since if the "encrypt" array is set, this variable should be setted to use in mysql_real_connect.

Should i report on GitHub?


RE: Can't connect to MySQL (Azure) using SSL encrypt connection - paulbalandan - 04-26-2021

yes please