PDOStatement 类

PDOStatement 类

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 1.0.0)

简介

代表一条预处理语句,并在该语句被执行后代表一个相关的结果集。

类摘要

PDOStatement  implements Traversable {
/* 属性 */
readonly  string  $queryString;
/* 方法 */
bool  bindColumn (  mixed $column ,  mixed &$param [,  int $type [,  int $maxlen [,  mixed $driverdata]]] )
bool  bindParam (  mixed $parameter ,  mixed &$variable [,  int $data_type = PDO::PARAM_STR [,  int$length [,  mixed $driver_options ]]] )
bool  bindValue (  mixed $parameter ,  mixed $value [,  int $data_type = PDO::PARAM_STR ] )
bool  closeCursor (  void )
int  columnCount (  void )
bool  debugDumpParams (  void )
string  errorCode (  void )
array  errorInfo (  void )
bool  execute ([  array $input_parameters ] )
mixed  fetch ([  int $fetch_style [,  int $cursor_orientation = PDO::FETCH_ORI_NEXT [,  int$cursor_offset = 0 ]]] )
array  fetchAll ([  int $fetch_style [,  mixed $fetch_argument [,  array $ctor_args = array() ]]] )
string  fetchColumn ([  int $column_number = 0 ] )
mixed  fetchObject ([  string $class_name = "stdClass" [,  array $ctor_args ]] )
mixed  getAttribute (  int $attribute )
array  getColumnMeta (  int $column )
bool  nextRowset (  void )
int  rowCount (  void )
bool  setAttribute (  int $attribute ,  mixed $value )
bool  setFetchMode (  int $mode )
}

属性

queryString

所用的查询字符串

Table of Contents

add a note add a note

User Contributed Notes 2 notes

up
1
luis-m-cardoso at ext dot ptinovacao dot pt  ¶
3 years ago
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";

?>
up
-38
rosko at zeta dot org dot au  ¶
7 years ago
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();
?>
                                                                                                                  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值