CodeIgniter活动记录调用多个存储过程的问题 [英] CodeIgniter active records' problems calling multiple stored procedures
问题描述
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);
}
}
}
问题与CodeIgniter的活动记录器和多个数据库存储过程调用有关.
首先检查dbdriver参数( application/config/database.php )是否设置为 mysqli . 然后,如从CodeIgniter的活动记录中调用存储过程"中所述类"问题在StackOverflow上,将以下功能添加到 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);
在任何存储过程调用之后.
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();
}
this is my controller code which calls three functions from model one by one:
$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);
my problem is when i run only one function it runs successfully but when i run two of them or all three it shows blank page... any idea why ???
SOLUTION
So finally the only solution we got for my own problem is :
/* 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);
}
}
}
The problem is related to CodeIgniter's active recors and multiple database stored procedure calling.
First of all check that dbdriver parameter (application/config/database.php) is set to mysqli. Then, as described in "Calling a stored procedure from CodeIgniter's Active Record class" question on StackOverflow, adding to system/database/DB_active_rec.php the following function:
function freeDBResource($dbh){
while(mysqli_next_result($dbh)){
if($l_result = mysqli_store_result($dbh)){
mysqli_free_result($l_result);
}
}
}
..And in your controller use:
$this->db->freeDBResource($this->db->conn_id);
after any stored procedure calling.
这篇关于CodeIgniter活动记录调用多个存储过程的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!