Hi I\'m kinda new to this and I would like to ask someone here that are experts in codeigniter framework and PHP.
How can I use mysqli drivers in php native query? F
go to:
yourproject/application/config/database.php
change:
$db['default']['dbdriver'] = 'mysql';
with:
$db['default']['dbdriver'] = 'mysqli';
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';
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']);
}
Open the file 'database.php' under the folder '/application/config/'
Move to the line
$db['default'] = array('dbdriver' => '')
Modify it as below
$db['default'] = array('dbdriver' => 'mysqli')