I have been using CI just fine using the MySQL driver. I want to use the MySQL driver instead, but as soon as I change it (just add the ‘i’ at the end of MySQL, and added the port number) I get the following error message
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 232
my setting look like this:
$db['default']['hostname'] = $hostname;
$db['default']['username'] = $username;
$db['default']['password'] = $password;
$db['default']['database'] = $database;
$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;
where
$hostname = 'localhost';
$username = 'myusernamegoeshere';
$password = 'mypasswordgoeshere';
$database = 'mydatabasenamegoeshere';
I'm Using:
CI 2.0.2 php 5.3.4 Apache/2.2.17 (Unix) mysql 5.5.13 mysql.default_port 3306
Am I doing anything wrong?
Thank you,
This question is related to
php
mysql
codeigniter
connection
mysqli
SET $db['default']['db_debug']
to FALSE instead of TRUE .
$db['default']['db_debug'] = FALSE;
If you used this to secure your server: http://www.thonky.com/how-to/prevent-base-64-decode-hack/
And then got the error: Code Igniter needs mysql_pconnect() in order to run
.
I figured it out once I realized all the Code Igniter websites on the server were broken, so it wasn't a localized connection issue.
I solved the problem by changing
$db['default']['pconnect'] = TRUE;
TO
$db['default']['pconnect'] = FALSE;
in /application/config/database.php
Extending @Valeh Hajiyev great and clear answer for mysqli
driver tests:
Debug your database connection using this script at the end of ./config/database.php:
/* Your db config here */
$db['default'] = array(
// ...
'dbdriver' => 'mysqli',
// ...
);
/* Connection test: */
echo '<pre>';
print_r($db['default']);
echo '</pre>';
echo 'Connecting to database: ' .$db['default']['database'];
$mysqli_connection = new MySQLi($db['default']['hostname'],
$db['default']['username'],
$db['default']['password'],
$db['default']['database']);
if ($mysqli_connection->connect_error) {
echo "Not connected, error: " . $mysqli_connection->connect_error;
}
else {
echo "Connected.";
}
die( 'file: ' .__FILE__ . ' Line: ' .__LINE__);
In my case storage was a problem. My hard drive was full... Make some space in hardware and your site will work fine
Today I fallen this kind of problem in live server and i solved the problem changing this line
$db['default']['db_debug'] = TRUE;
to
$db['default']['db_debug'] = FALSE;
(CI 3) For me, what worked was changing:
'hostname' => 'localhost' to 'hostname' => '127.0.0.1'
If that is all you have changed, you may not have the mysqli driver installed or enabled within your PHP configuration.
Check for its presence using phpinfo(), or in your php.ini file (extension=php_mysqli....).
Problem solved!
I was having all my website set up first in XAMMP, then I had to transfer it to LAMP, in a SUSE installation of LAMP, where I got this error.
The problem is that these parameters in the database.php file should not be initialised. Just leave username and password blank. That's just it.
(My first and lame guess would be that's because of old version of mysql, as built-in installations come with older versions.
Change $db['default']['dbdriver'] = 'mysql'
to $db['default']['dbdriver'] = 'mysqli'
I think, there is something wrong with PHP configration.
First, debug your database connection using this script at the end of ./config/database.php :
...
...
...
echo '<pre>';
print_r($db['default']);
echo '</pre>';
echo 'Connecting to database: ' .$db['default']['database'];
$dbh=mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'])
or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db['default']['database']);
echo '<br /> Connected OK:' ;
die( 'file: ' .__FILE__ . ' Line: ' .__LINE__);
Then see what the problem is.
I've solved this. In my case I just changed my configuration. 'hostname' became 'localhost'
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
In your configurations, specify the port number your database is on. You can find the port number at the top left corner of phpMyAdmin. It would look something like this
const DB_HOST = 'localhost:3308';
Source: Stackoverflow.com