Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MySQLi Driver in CodeIgniter

How can I use mysqli drivers in PHP native query?

For example. My code:

Model

class Home_model extends CI_Model{
    public function getusers(){
        $q = "SELECT * FROM `users`";
        return $r = mysqli_query($q);
    }
}

Controller:

class Home extends CI_Controller{
    public function iterateuser(){
        while($row = mysqli_fetch_object($this->Home_model->getusers())) {
            echo $row->username;
        }
    }

My code above has an error, saying:

mysqli_query expects at least 2 parameters

Is there a way in CodeIgniter to pass the link on the mysqli_query() first parameter as described on the php.net documentation http://php.net/manual/en/mysqli.query.php

like image 734
blessedthang Avatar asked Aug 02 '14 10:08

blessedthang


1 Answers

go to:

yourproject/application/config/database.php

change:

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

with:

$db['default']['dbdriver'] = 'mysqli';
like image 114
codematrix Avatar answered Sep 30 '22 07:09

codematrix