Postgres function:
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
In general, function returns product data in cursor (if any data found) and additionally err_number and err_desc if error occured.
Now I want to access from PHP data returned by function in po_cursor. What I am doing is:
<?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();
?>
As a result I recive sth like that:
Array
(
[0] => Array
(
[lcp_product_find] => (po_cursor,,)
[0] => (po_cursor,,)
)
)
Can you help me in sorting that out? What am I doing wrong that I do not get data returned in po_cursor? Can it be done without PDO?