尝试使用 PHP 访问 Oracle 的 select 函数
您好,我正在尝试访问一个返回选择查询结果的简单函数,当我使用 PHP 访问它时,它向我返回资源(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;
这相当简单。现在我无法理解为什么我收到资源(5),这表明存在错误。当我 var_dump 结果时我收到的实际消息是
数组(1) { ["SELECTME(:NAME)"]=>; 类型的资源(5)(oci8 语句)
Hello I am trying to access a simple function that returns the result of a select query, and when I am accessing it using PHP, it is throwing back a resource(5) at me rather than the result.
$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);
The selectMe function is pretty simple and just retrieves data from a table and returns the few rows that match the condition.
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;
Which is fairly simple. Now I am unable to understand why I am getting a resource(5) which is an indication of an error. The actual message I am getting when I var_dump the result is
array(1) { ["SELECTME(:NAME)"]=>
resource(5) of type (oci8 statement)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是 PHP 开发人员。但是,我可以从 Oracle PHP wiki 猜测它看起来像这样
I'm not a PHP developer. However, I can steal liberally from the Oracle PHP wiki to guess that it would look something like
selectMe() 定义的一个有效示例是:
A working example for your definition of selectMe() is: