Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中访问从postgres函数返回的游标中的数据_Php_Postgresql_Pdo - Fatal编程技术网

如何在PHP中访问从postgres函数返回的游标中的数据

如何在PHP中访问从postgres函数返回的游标中的数据,php,postgresql,pdo,Php,Postgresql,Pdo,博士后功能: CREATE OR REPLACE FUNCTION lcp_product_find(IN pi_prd_code text DEFAULT NULL::text, OUT po_cursor refcursor, OUT po_err_num integer, OUT po_err_desc text) RETURNS record AS $BODY$ DECLARE v_proc_name text; v_prd_id integer; BEGIN v_proc_nam

博士后功能:

CREATE OR REPLACE FUNCTION lcp_product_find(IN pi_prd_code text DEFAULT NULL::text, OUT  po_cursor refcursor, OUT po_err_num integer, OUT po_err_desc text)
RETURNS record AS
$BODY$  
DECLARE
v_proc_name text;
v_prd_id integer;
BEGIN
v_proc_name := 'lcp_product_find';
po_cursor := 'po_cursor';

-- some selects from lct_products table

OPEN po_cursor FOR 
    select "PRD_ID", "PRD_FAMILY", "PRD_NAME", "PRD_DESC", "PRD_BRAND", 
    "PRD_MODEL", "PRD_STATUS", "PRD_AUDIT_CD", "PRD_AUDIT_MD", "PRD_CODE" 
    from lct_products where "PRD_ID" = v_prd_id;
    RETURN;

END;
$BODY$
LANGUAGE plpgsql VOLATILE
通常,如果发现任何数据,函数将在游标中返回产品数据,如果发生错误,函数还将返回err_number和err_desc

现在我想访问po_cursor中函数返回的PHP数据。我正在做的是:

<?php
$conn = new PDO("pgsql:host=localhost;port=5432;dbname=name", "user", "pas");

$conn->beginTransaction();

$prd_code = $_POST['prd_code'];     //echo $prd_code;

// call the function
$stmt = $conn->prepare("select lcp_product_find(:pi_prd_code)");
$stmt->bindParam('pi_prd_code', $prd_code, PDO::PARAM_STR);
$stmt->execute();
$cursors = $stmt->fetchAll();
$stmt->closeCursor();

?>

你能帮我整理一下吗?我没有在po_游标中返回数据,这有什么错?没有PDO可以完成吗?

SQL游标一旦打开并返回到php,就必须由SQL语句、、。。。通过它的名字。此功能不是作为PDO功能实现的,而且在数据库之间不兼容

指与上下文无关的客户端游标

例如:

$s = $db->query("FETCH ALL FROM po_cursor");
$rows = $s->fetchAll();
$db->query("CLOSE po_cursor");
如果使用动态游标名称,请注意它们在语法上是SQL标识符,这意味着在不严格使用字母数字时,它们的引号必须与列或表名相同,并且在不使用引号时,它们不区分大小写

为pg_*API实现此引用,但PDO中似乎没有等效函数

当程序不命名游标时,PostgreSQL会生成名称,如,其空格需要在可注入查询之前全部引用,如:

fetch all from "<unnamed portal 1>"
fetch all from "<unnamed portal 1>"