CodeIgniter Forums
CI: Mysqli - Broken - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: CI: Mysqli - Broken (/showthread.php?tid=65131)



CI: Mysqli - Broken - phpscott - 05-03-2016

So, I've been working with CI since 1.x

Today I've come across the following error

I have a database configured as mysqli.
All my credentials are correct. <- yes they are.

I get this from Codeigniter:
Unable to connect to your database server using the provided settings.
From logs:
ERROR - 2016-05-03 23:01:43 --> Severity: Warning --> mysqli::real_connect(): (HY000/2002): Permission denied /.../database/drivers/mysqli/mysqli_driver.php 202

However, doing a simple php script on the same server using the same credentials connects to the database without issue.
Literally copied and pasted the credentials.
The php script that works is straight from php.net:

\
PHP Code:
<?php


$mysqli 
mysqli_init();
if (!
$mysqli) {
 
   die('mysqli_init failed');
}

if (!
$mysqli->options(MYSQLI_INIT_COMMAND'SET AUTOCOMMIT = 0')) {
 
   die('Setting MYSQLI_INIT_COMMAND failed');
}

if (!
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT5)) {
 
   die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}

if (!
$mysqli->real_connect('DBHOST''DBUSER''DBPASS''DBNAME')) {
 
   die('Connect Error (' mysqli_connect_errno() . ') '
 
           mysqli_connect_error());
}

echo 
'Success... ' $mysqli->host_info "\n";

$mysqli->close(); 



RE: CI: Mysqli - Broken - thienhaxanh2405 - 05-04-2016

Do you try with socket option? Try to config default socket in your system.

e.g: in my localhost, I'm using XAMPP on Mac OS and mysqli defaul socket is: /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

PHP Code:
$servername "127.0.0.1";
$username "username";
$password "password";
$port 3306;
$socket "/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock";
// Create connection
$conn = new mysqli($servername$username$password$port$socket);
var_dump($conn); 

Note: use 127.0.0.1 instead localhost


RE: CI: Mysqli - Broken - phpscott - 05-04-2016

Hey thienhaxanh2405, thanks for the response, sorry did not mention this is an RDS (AWS) server.

The mysqli code works outside of Codeigniter for the remote server connection.
Just not the codeigniter driver itself.

During the writing of this reply, looked into 1 more thing and discovered this:

Code:
setsebool -P httpd_can_network_connect_db=1

My working stand alone script was being run command line so, when I tried running it via an http request, I got the error.

#$^$#%^ you SElinux.

Thanks, hope this helps someone else!


RE: CI: Mysqli - Broken - thienhaxanh2405 - 05-06-2016

Great, it works.

(05-04-2016, 07:43 AM)phpscot Wrote: SElinux.

Ha ha, very helpful for security reasons but for common user or beginner, SElinux is so complicated.