PHP Doku:: The PDOStatement class - class.pdostatement.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAbstraktionsebenenPHP Data ObjectsThe PDOStatement class

Ein Service von Reinhard Neidl - Webprogrammierung.

PHP Data Objects

<<PDO::setAttribute

PDOStatement->bindColumn>>


UnterSeiten:

The PDOStatement class

Einführung

Represents a prepared statement and, after the statement is executed, an associated result set.

Klassenbeschreibung

PDOStatement implements Traversable {
/* Eigenschaften */
readonlystring $queryString;
/* Methoden */
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 = array() ] )
mixed fetch ([ int $fetch_style = PDO::FETCH_BOTH [, int $cursor_orientation = PDO::FETCH_ORI_NEXT [, int $cursor_offset = 0 ]]] )
array fetchAll ([ int $fetch_style = PDO::FETCH_BOTH [, 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 )
}

Eigenschaften

queryString

Used query string.

Inhaltsverzeichnis


3 BenutzerBeiträge:
- Beiträge aktualisieren...
arnmundur at visir dot is
23.09.2010 12:46
Do not use BindParam inside a foreach loop use BindValue...
rosko at zeta dot org dot au
3.12.2009 2:50
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();
?>
james dot ellis at gmail dot com
7.07.2009 3:25
The query string used in a PDOStatement can be found using the (undocumented) property 'queryString'

<?php
//$stm is a prepared PDOStatement
print $stm->queryString
//example result
//SELECT firstname, lastname FROM user where id = :id
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)