您好,我试图访问一个简单的函数,该函数返回选择查询的结果,当我使用PHP访问它时,它向我扔了resource(5)而不是结果.
$connect = oci_connect('tiger','scott','host/user');
if(!$connect){
$e = oci_error();
trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);
}
$qu = oci_parse($connect, 'select selectMe(:name) from dual');
$name = (string)'test1';
oci_bind_by_name($qu,":name",$name);
oci_execute($qu);
$row = oci_fetch_assoc($qu);
var_dump($row);
selectMe函数非常简单,它仅从表中检索数据并返回符合条件的几行.
CREATE OR REPLACE FUNCTION selectMe( temp_name varchar2(100) )
return SYS_REFCURSOR is my_ret SYS_REFCURSOR;
BEGIN
open my_ret
FOR select myTab_ID, myTab_NAME, myTab_AGE, myTab_SCORE
from myTab
where trim(myTab_name) = temp_name;
RETURN my_ret;
END;
这很简单.现在,我无法理解为什么我得到了resource(5)来指示错误.我在var_dump结果中得到的实际消息是
array(1) { [“SELECTME(:NAME)”]=>
resource(5) of type (oci8 statement)
解决方法:
我不是PHP开发人员.但是,我可以从Oracle PHP wiki处偷取,以猜测它看起来像
$conn = oci_connect('myusername', 'mypassword', 'mydb');
$stid = oci_parse($conn, "begin :rc := selectMe(:name); end;");
$refcur = oci_new_cursor($conn);
oci_bind_by_name($stid, ':rc', $refcur, -1, OCI_B_CURSOR);
oci_bind_by_name($stid, ':name', 'test1');
oci_execute($stid);
oci_execute($refcur);
oci_fetch_all($refcur, $res);
var_dump($res);
oci_free_statement($stid);
oci_close($conn);
标签:oracle,plsql,sql,php,function
来源: https://codeday.me/bug/20191023/1914043.html