©
このドキュメントでは、 php中国語ネットマニュアル リリース
(PHP 5 >= 5.1.0, PECL pdo >= 1.0.0)
代表一条预处理语句,并在该语句被执行后代表一个相关的结果集。
$column
, mixed &$param
[, int $type
[, int $maxlen
[, mixed $driverdata
]]] )$parameter
, mixed &$variable
[, int $data_type
= PDO::PARAM_STR
[, int $length
[, mixed $driver_options
]]] )$parameter
, mixed $value
[, int $data_type
= PDO::PARAM_STR
] )$input_parameters
] )$fetch_style
[, int $cursor_orientation
= PDO::FETCH_ORI_NEXT
[, int $cursor_offset
= 0
]]] )$fetch_style
[, mixed $fetch_argument
[, array $ctor_args
= array()
]]] )$column_number
= 0
] )$class_name
= "stdClass"
[, array $ctor_args
]] )$attribute
)$column
)$attribute
, mixed $value
)$mode
)所用的查询字符串
[#1] luis-m-cardoso at ext dot ptinovacao dot pt [2013-09-16 14:53:52]
Solved ;)
<?php
$host = "yourHost";
$user = "yourUser";
$pass = "yourPass";
$db = "yourDB";
$cursor = "cr_123456";
try
{
$dbh = new PDO("pgsql:host=$host;port=5432;dbname=$db;user=$user;password=$pass");
echo "Connected<p>";
}
catch (Exception $e)
{
echo "Unable to connect: " . $e->getMessage() ."<p>";
}
$dbh->beginTransaction();
$query = "SELECT yourFunction(0::smallint,'2013-08-01 00:00','2013-09-01 00:00',1::smallint,'$cursor')";
$dbh->query($query);
$query = "FETCH ALL IN \"$cursor\"";
echo "begin data<p>";
foreach ($dbh->query($query) as $row)
{
echo "$row[0] $row[1] $row[2] <br>";
}
echo "end data";
?>
[#2] rosko at zeta dot org dot au [2009-12-02 17:50:40]
There are many references around for returning a refcursor from a pgSQL function using pg_query. All essentially boil down to executing the following single statement (or some variation of it):
begin; select yourFunction(params...); fetch all in cursorname; commit;
In PDO, this doesn't work because PDO won't allow multiple statements submitted as a single statement (due to SQL injection detection). Instead, try this or similar:
<?php
$sql = 'select yourFunction(params...)';
$db = new PDO('pgsql:dbname=yourDBname');
$db->beginTransaction();
$cmd = $db->prepare($sql);
if ($cmd->execute()) {
if ($query = $db->query('fetch all in cursorname')) {
...processing...
$query->closeCursor();
$cmd->closeCursor();
}
}
$db->commit();
?>