======================== PLPGSQL:
CREATE OR REPLACE FUNCTION get_user_data(REFCURSOR, INTEGER) RETURNS REFCURSOR AS '
DECLARE v_cursor ALIAS FOR $1; v_user_id ALIAS FOR $2;
BEGIN
OPEN v_cursor FOR SELECT * FROM users WHERE user_id = v_user_id;
RETURN v_cursor;
END;
' LANGUAGE 'plpgsql';
========================== PHP:
$cursor = 'my_user';
$query = "SELECT get_user_data('$cursor', $user_id);FETCH ALL IN $cursor;";
$res =& $dbh->query($query);
if (DB::isError($res)) { ... process the error }
$row = $res->fetchRow(DB_FETCHMODE_ASSOC);
$dbh->query("CLOSE $cursor;");
$res->free();
return $row; ============================
Question #1: Is this the way to do it?
Question #2: I'm using a persistent database connection. To avoid leaving an open cursor laying around I make another call to close the cursor after the result set is fetched. Do I need to do this or will the cursor be closed implicitly by Apache/PHP after the page is delivered?
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster