尝试通过在代码点火器中调用存储过程来从数据库获取结果。以下是我的控制器&模型。模型正常工作从存储过程获取结果,并且可以在模型中执行print_r()
时显示结果。但是我无法在控制器方法中获得查询结果。无法理解这里的错误。
控制器:
function weeklysalesstatus()
{
$this->data['rpt'] =$this->reports_model->weeklysalesstatus(true);
$this->data['page_title'] ='Weekly Sales Status [ Residential ]';
print_r("here...");
$this->page_construct('reports/weeklysalesstatus', $this->data);
}
型号:
public function weeklysalesstatus($sender = false)
{
$sql = 'select * from region';
$sql1 = 'CALL GetWeeklySalesStatus()';
$query = $this->db->query($sql1);
if(count($query) > 0) {
foreach (($query->result()) as $row) {
$data[] = $row;
//var_dump($data);
}
return $data;
} else {
print_r("no rows");
}
return $data;
}
问题出在这一行:$this->data[$rpt] = $this->reports_model->weeklysalesstatus();
但无法弄清楚。
感谢
编辑:
只有在我调用Stored Procedure CALL时才会出现这些错误。对于其他查询,它完美地工作。那么我在Codeigniter DB类上需要做什么设置才能通过活动记录调用存储过程?
答案 0 :(得分:0)
$ q = $ this-> db-> query(' CALL GetWeeklySalesStatus');
将此行更改为
$ q = $ this-> db-> query(' CALL GetWeeklySalesStatus') - > result();
答案 1 :(得分:0)
在模型中
public function weeklysalesstatus()
{
//$sql = 'select * from region';
$sql1 = 'CALL GetWeeklySalesStatus()';
$query = $this->db->query($sql1);
if(!empty($query))
{
$data = $query->result_array();
return $data;
}
else
{
return FALSE;
}
}
在控制器中
function weeklysalesstatus()
{
$rpt =$this->reports_model->weeklysalesstatus();
if ($rpt == FALSE) {
echo "Empty";
} else {
$data['rpt'] = $rpt;
}
$data['page_title'] ='Weekly Sales Status [ Residential ]';
$this->page_construct('reports/weeklysalesstatus', $data);
}
答案 2 :(得分:0)
修改控制器,如下所示希望它能正常工作
function weeklysalesstatus()
{
$this->data['rpt'] =$this->reports_model->weeklysalesstatus();
$this->data['page_title'] ='Weekly Sales Status';
$this->page_construct('reports/weeklysalesstatus', $this->data);
}
答案 3 :(得分:0)
你的模特
public function weeklysalesstatus($sender = false)
{
$sql = 'select * from region';
$sql1 = 'CALL GetWeeklySalesStatus()';
$query = $this->db->query($sql1);
$data["result"] = array();
if(count($query) > 0) {
foreach (($query->result()) as $row) {
$data["result"][] = $row;
//var_dump($data);
}
}
return $data;
}
你的控制器
function weeklysalesstatus()
{
$data['rpt'] =$this->reports_model->weeklysalesstatus(true);
$data['page_title'] ='Weekly Sales Status [ Residential ]';
print_r("here...");
$this->page_construct('reports/weeklysalesstatus', $data);
}