How to use MySQLi Driver in Codeigniter

前端 未结 4 869
醉梦人生
醉梦人生 2020-12-17 23:29

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

相关标签:
4条回答
  • 2020-12-18 00:08

    go to:

    yourproject/application/config/database.php
    

    change:

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

    with:

    $db['default']['dbdriver'] = 'mysqli';
    
    0 讨论(0)
  • 2020-12-18 00:10

    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'; 
    
    0 讨论(0)
  • 2020-12-18 00:15

    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']);
    }
    
    0 讨论(0)
  • 2020-12-18 00:25

    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')
    
    0 讨论(0)
提交回复
热议问题