How to use MySQLi Driver in CodeIgniter How to use MySQLi Driver in CodeIgniter codeigniter codeigniter

How to use MySQLi Driver in CodeIgniter


go to:

yourproject/application/config/database.php

change:

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

with:

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


Once you have specified 'mysqli',you can use the following function to get mysqli. For example, mysqli_real_escape_str, etc.:

function get_mysqli() {     $db = (array)get_instance()->db;    return mysqli_connect('localhost', $db['username'], $db['password'], $db['database']);}


You should change the content of the file DB_driver.php in you codeigniter system directory. Go to:

system/database/DB_driver.php

And change the following line:

var $dbdriver = 'mysql'; 

to :

var $dbdriver = 'mysqli'; 

here is a extraction of the DB_driver.php

 * MySQLi Database Adapter Class - MySQLi only works with PHP 5 * * Note: _DB is an extender class that the app controller * creates dynamically based on whether the active record * class is being used or not. * * @package        CodeIgniter * @subpackage    Drivers * @category    Database * @author        ExpressionEngine Dev Team * @link        http://ellislab.com/codeigniter/user-guide/database/ */class CI_DB_mysqli_driver extends CI_DB {    var $dbdriver = 'mysqli';