Sam*_*nde 5 stored-procedures codeigniter
我正在使用具有mysqli作为db驱动程序的codeigniter,我试图从我的模型调用一个简单的存储过程但是得到一个错误.我究竟做错了什么
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pc()' at line 1
pc()
Filename: C:\hosted\saner.gy\ipa\system\database\DB_driver.php
Line Number: 330
Run Code Online (Sandbox Code Playgroud)
当我运行查询调用存储过程它运行良好,但从codeigniter它会抛出上述错误
存储过程
CREATE DEFINER=`root`@`localhost` PROCEDURE `pc`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
SELECT * FROM tbl_flo
WHERE name = 'sam';
END
Run Code Online (Sandbox Code Playgroud)
调节器
public function sp()
{
$this->User_model->pc();
}
Run Code Online (Sandbox Code Playgroud)
模型
public function pc()
{
$query = $this->db->query("pc()");
return $query->result();
}
Run Code Online (Sandbox Code Playgroud)
使用CALL procedure_name(optional_params)查询调用存储过程。
您需要像这样编辑模型中使用的查询:
public function pc()
{
$query = $this->db->query("CALL pc()");
return $query->result();
}
Run Code Online (Sandbox Code Playgroud)
小智 2
您正在使用以下方式来调用过程。
$this->db->call_function('pc');
Run Code Online (Sandbox Code Playgroud)
或者你也可以使用这个
$this->db->query("call pc()");
Run Code Online (Sandbox Code Playgroud)