php 如何在 CodeIgniter 中调用存储过程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18201045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call a stored procedure in CodeIgniter?
提问by Snap Mash
I can't call a stored procedure in CodeIgniter. However, when I call the procedure directly in MySQL, it works. Why isn't it working when I call it in CodeIgniter?
我无法在 CodeIgniter 中调用存储过程。但是,当我直接在 MySQL 中调用该过程时,它可以工作。为什么当我在 CodeIgniter 中调用它时它不起作用?
CREATE DEFINER=`root`@`localhost` PROCEDURE `test_proc`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
declare name1 TEXT;
declare id1 TEXT;
select name,id into name1,id1 from my_tbl WHERE name='sam';
select * from my_tbl;
select name1,id1;
END
回答by Jeyasithar
I think you are using the following way to call procedure.
我认为您正在使用以下方式来调用过程。
$this->db->call_function('test_proc');
Its wrong. Only default procedures can be called using this method. To call procedures defined by you, you have to go with
这是错的。使用此方法只能调用默认过程。要调用您定义的过程,您必须使用
$this->db->query("call test_proc()");
回答by Tariq
For Oracle procedured here is a simple way to call
对于 Oracle 程序,这里是一个简单的调用方式
$rsponse = '';
$s = oci_parse($this->db->conn_id, "begin packageName.procedureName(:bind1,:bind2,:bind3,:bind4,:bind5); end;");
oci_bind_by_name($s, ":bind1", $data['fieldOne'],300);
oci_bind_by_name($s, ":bind2", $data['fieldTwo'],300);
oci_bind_by_name($s, ":bind3", $data['fieldThre'],300);
oci_bind_by_name($s, ":bind4", $data['fieldFour'],300);
oci_bind_by_name($s, ":bind4", $response,300);
oci_execute($s, OCI_DEFAULT);
echo $message;
In the above example procedure accept four arguments as input and one parameter as output. in case of direct calling procedure remove 'packageName.' That's it...
在上面的示例过程中,接受四个参数作为输入,一个参数作为输出。在直接调用过程的情况下删除“packageName”。就是这样...