Calling stored procedure in codeigniter

前端 未结 4 507
执笔经年
执笔经年 2020-12-14 12:37

I am using latest codeigniter and trying to call stored procedure from my model. Also I am using mysqli as database driver. Now I am having an error when I call two stored p

4条回答
  •  醉梦人生
    2020-12-14 13:18

    I follow the blog of Mr. Tim Brownlaw:
    http://ellislab.com/forums/viewthread/73714/#562711

    First, modify application/config/config.php, line 55.

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

    Then, add the following into mysqli_result.php that is missing this command for some strange reason (under /system/database/drivers/mysqli/mysqli_result.php).

    /**
      * Read the next result
      *
      * @return  null
      */   
     function next_result()
     {
         if (is_object($this->conn_id))
         {
             return mysqli_next_result($this->conn_id);
         }
     }
    

    Then, in your model, add $result->next_result().

    Below is my example.

    function list_sample($str_where, $str_order, $str_limit)
    {
       $qry_res    = $this->db->query("CALL rt_sample_list('{$str_where}', '{$str_order}', '{$str_limit}');");
    
       $res        = $qry_res->result();
    
       $qry_res->next_result(); // Dump the extra resultset.
       $qry_res->free_result(); // Does what it says.
    
       return $res;
    }
    

提交回复
热议问题