4
class Registration_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }   

    function check_email_availability($email)
    {
        $sql = "CALL proc_1301('$email');"; 
        $query = $this->db->query($sql) or die(mysql_error()); 
        return $query->row_array();
    }

    function check_username_availability($username)
    {
        $sqlt = "CALL proc_1303('$username');"; 
        $query = $this->db->query($sqlt) or die(mysql_error()); 
        return $query->row_array();
    }

    function process_registration($username, $email, $password)
    { 
        $sql = "CALL `proc_1302`('$username', '$email', '$password');"; 
        $query = $this->db->query($sql) or die(mysql_error()); 
        return $query->result_array();   
    }

这是我的控制器代码,它从模型中一一调用三个函数:

$emailCheckRes = $this->Registration_model->check_email_availability($email); 
$usernameCheckRes = $this->Registration_model->check_username_availability($username); 
$this->data['regRes'] = $this->Registration_model->process_registration($username, $email, $password);

我的问题是,当我只运行一个功能时,它运行成功,但是当我运行其中两个或全部三个时,它显示空白页...知道为什么吗???

解决方案

所以最后我们为自己的问题得到的唯一解决方案是:

/* ADD THIS FUNCTION IN SYSTEM/DATABASE/DB_ACTIVE_REC */
/* USAGE $this->db->freeDBResource($this->db->conn_id); */
function freeDBResource($dbh){
    while(mysqli_next_result($dbh)){
            if($l_result = mysqli_store_result($dbh)){
              mysqli_free_result($l_result);
            }
        }
}
4

2 回答 2

6

该问题与 CodeIgniter 的活动记录和多个数据库存储过程调用有关。

首先检查 dbdriver 参数(application/config/database.php)是否设置为mysqli。然后,如StackOverflow 上的“从 CodeIgniter 的 Active Record 类调用存储过程”问题中所述,将以下函数添加到system/database/DB_active_rec.php :

function freeDBResource($dbh){
    while(mysqli_next_result($dbh)){
            if($l_result = mysqli_store_result($dbh)){
              mysqli_free_result($l_result);
            }
        }
}

..并在您的控制器中使用:

$this->db->freeDBResource($this->db->conn_id);

在任何存储过程调用之后。

于 2012-07-30T17:50:33.130 回答
0

模型和控制器似乎没问题。如果您尝试以下模型:

class Test_model extends CI_Model
{
   function __construct()
   {
      parent::__construct();
   }
   function a($a_input)
   {
      return($a_input.': a');
   }
   function b($b_input)
   {
     return($b_input.': b');
   }
}

...并从这样的控制器调用它的功能:

$this->load->model('Test_model');
    $a_result = $this->Test_model->a('aaa');
    $b_result = $this->Test_model->b('bbb');
    echo($a_result.'<br />'.$b_result);

您可以看到多个函数调用工作正常。

如果只调用一个,您确定可以正确执行模型中的三个函数中的任何一个吗?如果是,也许问题可以在您的存储过程中找到......您可以尝试在模型函数中执行普通查询而不是存储过程吗?为了调试您的问题,如果 db_debug 设置为 TRUE,请同时检查您的 /application/config/database.php。

于 2012-07-30T12:32:48.187 回答