diff --git a/reference/pdo/constants.xml b/reference/pdo/constants.xml index 5c4b86ac17..bd9edc9cc5 100644 --- a/reference/pdo/constants.xml +++ b/reference/pdo/constants.xml @@ -1,5 +1,5 @@ - +
&reftitle.constants; @@ -461,7 +461,7 @@ Create a PDOStatement object with a forward-only cursor. This may improve - the performance of your application but restricts your PROStatement object + the performance of your application but restricts your PDOStatement object to fetching one row at a time from the result set in a forward direction. diff --git a/reference/pdo/functions/PDO-beginTransaction.xml b/reference/pdo/functions/PDO-beginTransaction.xml index fbe73456c8..9ccd8b966e 100644 --- a/reference/pdo/functions/PDO-beginTransaction.xml +++ b/reference/pdo/functions/PDO-beginTransaction.xml @@ -1,5 +1,5 @@ - + @@ -8,8 +8,9 @@ Initiates a transaction - - Description + + + &reftitle.description; boolPDO::beginTransaction @@ -21,6 +22,43 @@ autocommit mode. + + + &reftitle.examples; + + Roll back a transaction + +beginTransaction(); + +/* Change the database schema and data */ +$sth = $dbh->exec("DROP TABLE fruit"); +$sth = $dbh->exec("UPDATE dessert + SET name = 'hamburger'"); + +/* Recognize mistake and roll back changes */ +$dbh->rollBack(); + +/* Database connection is now back in autocommit mode */ +?> +]]> + + + + + + + &reftitle.seealso; + + + PDO::commit + PDO::rollBack + + + + + @@ -8,8 +8,9 @@ Commits a transaction - - Description + + + &reftitle.description; boolPDO::commit @@ -21,6 +22,42 @@ starts a new transaction. + + + &reftitle.examples; + + Commit a transaction + +beginTransaction(); + +/* Change the database schema */ +$sth = $dbh->exec("DROP TABLE fruit"); + +/* Commit the changes */ +$dbh->commit(); + +/* Database connection is now back in autocommit mode */ +?> +]]> + + + + + + + &reftitle.seealso; + + + PDO::beginTransaction + PDO::rollBack + + + + + + PDO::__construct @@ -14,7 +14,7 @@ stringdsn stringusername stringpassword - arraydriver_opts + arraydriver_options &warn.experimental.func; @@ -83,10 +83,10 @@ - driver_opts + driver_options - A key => value array of driver-specific connection options. + A key=>value array of driver-specific connection options. diff --git a/reference/pdo/functions/PDO-prepare.xml b/reference/pdo/functions/PDO-prepare.xml index 69515097bc..ea299018ab 100644 --- a/reference/pdo/functions/PDO-prepare.xml +++ b/reference/pdo/functions/PDO-prepare.xml @@ -1,5 +1,5 @@ - + @@ -8,11 +8,12 @@ Prepares a statement for execution and returns a statement object - - Description + + &reftitle.description; PDOStatementPDO::prepare stringstatement + arraydriver_options &warn.experimental.func; @@ -41,6 +42,18 @@ + + driver_options + + + This array holds one or more key=>value pairs to set + attribute values for the PDOStatement object that this method + returns. You would most commonly use this to set the + PDO_ATTR_CURSOR value to + PDO_CURSOR_SCROLL to request a scrollable cursor. + + + @@ -55,26 +68,27 @@ &reftitle.examples; - - Prepare an SQL statement with named parameters - + + Prepare an SQL statement with named parameters + prepare('SELECT name, colour, calories +$sql = 'SELECT name, colour, calories FROM fruit - WHERE calories < :calories AND colour = :colour'); + WHERE calories < :calories AND colour = :colour' +$sth = $dbh->prepare($sql, array(PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY)); $sth->execute(array(':calories' => 150, ':colour' => 'red')); $red = $sth->fetchAll(); $sth->execute(array(':calories' => 175, ':colour' => 'yellow')); $yellow = $sth->fetchAll(); ?> ]]> - - - - Prepare an SQL statement with question mark parameters - + + + + Prepare an SQL statement with question mark parameters + execute(array(175, 'yellow')); $yellow = $sth->fetchAll(); ?> ]]> - - + + + diff --git a/reference/pdo/functions/PDO-rollBack.xml b/reference/pdo/functions/PDO-rollBack.xml index 50ee942979..2d366ecd46 100644 --- a/reference/pdo/functions/PDO-rollBack.xml +++ b/reference/pdo/functions/PDO-rollBack.xml @@ -1,5 +1,5 @@ - + @@ -8,8 +8,9 @@ Rolls back a transaction - - Description + + + &reftitle.description; boolPDO::rollBack @@ -26,8 +27,13 @@ connection state to manual commit mode before issuing PDO::rollBack has any effect. - Roll back a transaction - + + + + &reftitle.examples; + + Roll back a transaction + exec("UPDATE dessert SET name = 'hamburger'"); /* Recognize mistake and roll back changes */ -$sth->rollBack(); +$dbh->rollBack(); /* Database connection is now back in autocommit mode */ ?> ]]> - - - + + + + + + &reftitle.seealso; + + + PDO::beginTransaction + PDO::commit + + + + + + @@ -8,53 +8,103 @@ Fetches the next row from a result set - - Description + + &reftitle.description; arrayPDOStatement::fetch intfetch_style + intcursor_orientation + intcursor_offset - &warn.experimental.func; + Fetches a row from a result set associated with a PDOStatement object. - - fetch_style can be one of the following values: - - - PDO_FETCH_ASSOC: returns an array indexed by column - name as returned in your result set - - - PDO_FETCH_BOTH (default): returns an array indexed by - both column name and column number as returned in your result set - - - PDO_FETCH_BOUND: returns &true; and assigns the - values of the columns in your result set to the PHP variables to which - they were bound with the PDOStatement::bindParam - method - - - PDO_FETCH_LAZY: combines - PDO_FETCH_BOTH and PDO_FETCH_OBJ, - creating the object variable names as they are accessed - - - PDO_FETCH_OBJ: returns an anonymous object with - property names that correspond to the column names returned in your - result set - - - PDO_FETCH_NUM: returns an array indexed by column - number as returned in your result set, starting at column 0 - - - + - Fetching rows using different fetch styles - + + &reftitle.parameters; + + + + fetch_style + + + Controls how the next row will be returned to the caller. This value + must be one of the PDO_FETCH_* constants, + defaulting to PDO_FETCH_BOTH. + + + PDO_FETCH_ASSOC: returns an array indexed by column + name as returned in your result set + + + PDO_FETCH_BOTH (default): returns an array indexed by + both column name and column number as returned in your result set + + + PDO_FETCH_BOUND: returns &true; and assigns the + values of the columns in your result set to the PHP variables to which + they were bound with the PDOStatement::bindParam + method + + + PDO_FETCH_LAZY: combines + PDO_FETCH_BOTH and PDO_FETCH_OBJ, + creating the object variable names as they are accessed + + + PDO_FETCH_OBJ: returns an anonymous object with + property names that correspond to the column names returned in your + result set + + + PDO_FETCH_NUM: returns an array indexed by column + number as returned in your result set, starting at column 0 + + + + + + + cursor_orientation + + + For a PDOStatement object representing a scrollable cursor, this + value determines which row will be returned to the caller. This value + must be one of the PDO_FETCH_ORI_* constants, + defaulting to PDO_FETCH_ORI_NEXT. + + + + + offset + + + For a PDOStatement object representing a scrollable cursor for which + the cursor_orientation parameter is set to + PDO_FETCH_ORI_ABS, this value specifies the + absolute number of the row in the result set that shall be fetched. + + + For a PDOStatement object representing a scrollable cursor for which + the cursor_orientation parameter is set to + PDO_FETCH_ORI_REL, this value specifies the + row to fetch relative to the cursor position before + PDOStatement::fetch was called. + + + + + + + + + &reftitle.examples; + + Fetching rows using different fetch styles + prepare("SELECT name, colour FROM fruit"); @@ -86,10 +136,9 @@ print $result->NAME; print("\n"); ?> ]]> - - - &example.outputs; - + + &example.outputs; + - + + + Fetching rows with a scrollable cursor + +prepare($sql, array(PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL)); + $stmt->execute(); + while ($row = $stmt->fetch(PDO_FETCH_NUM, PDO_FETCH_ORI_NEXT)) { + $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; + print $data; + } + $stmt = null; + } + catch (PDOException $e) { + print $e->getMessage(); + } +} +function readDataBackwards($dbh) { + $sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY bet'; + try { + $stmt = $dbh->prepare($sql, array(PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL)); + $stmt->execute(); + $row = $stmt->fetch(PDO_FETCH_NUM, PDO_FETCH_ORI_LAST); + do { + $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; + print $data; + } while ($row = $stmt->fetch(PDO_FETCH_NUM, PDO_FETCH_ORI_PRIOR)); + $stmt = null; + } + catch (PDOException $e) { + print $e->getMessage(); + } +} +print "Reading forwards:\n"; +readDataForwards($conn); + +print "Reading backwards:\n"; +readDataBackwards($conn); +?> +]]> + + &example.outputs; + + + + + + + + + + &reftitle.seealso; + + + PDO::query + PDOStatement::fetchAll + PDOStatement::fetchSingle + PDOStatement::prepare + PDOStatement::setFetchMode + + diff --git a/reference/pdo/functions/PDOStatement-fetchAll.xml b/reference/pdo/functions/PDOStatement-fetchAll.xml index ee89e0f89f..e5dbd8abc2 100644 --- a/reference/pdo/functions/PDOStatement-fetchAll.xml +++ b/reference/pdo/functions/PDOStatement-fetchAll.xml @@ -1,5 +1,5 @@ - + @@ -8,22 +8,41 @@ Returns an array containing all of the result set rows - - Description + + &reftitle.description; arrayPDOStatement::fetchAll intfetch_style &warn.experimental.func; + + + + &reftitle.parameters; + + + + fetch_style + + + Controls the contents of the returned array as documented in + PDOStatement::fetch. Defaults to + PDO_FETCH_BOTH. + + + + + + + + + &reftitle.returnvalues; PDOStatement::fetchAll returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties - corresponding to each column name. fetch_style - controls the contents of the returned array as documented in - PDOStatement::fetch. fetch_style - defaults to PDO_FETCH_BOTH. + corresponding to each column name. Using this method to fetch large result sets will result in a heavy @@ -33,9 +52,13 @@ SORT BY clauses in SQL to restrict results before retrieving and processing them with PHP. + - Fetch all remaining rows in a result set - + + &reftitle.examples; + + Fetch all remaining rows in a result set + prepare("SELECT name, colour FROM fruit"); @@ -47,9 +70,9 @@ $result = $sth->fetchAll(); print_r($result); ?> ]]> - - &example.outputs; - + + &example.outputs; + - - + + + + + + &reftitle.seealso; + + + PDO::query + PDOStatement::fetch + PDOStatement::fetchSingle + PDOStatement::prepare + PDOStatement::setFetchMode + + diff --git a/reference/pdo/functions/PDOStatement-fetchSingle.xml b/reference/pdo/functions/PDOStatement-fetchSingle.xml index c67a7cbb24..0ea0bd7f2e 100644 --- a/reference/pdo/functions/PDOStatement-fetchSingle.xml +++ b/reference/pdo/functions/PDOStatement-fetchSingle.xml @@ -1,5 +1,5 @@ - + @@ -8,25 +8,35 @@ Returns the first column in the next row of a result set - - Description + + + &reftitle.description; stringPDOStatement::fetchSingle &warn.experimental.func; - - PDOStatement::fetchSingle returns the first column - in the next row of a result set as a string value. - - - - There is no way to return the second or subsequent columns from a row - if you use this method to retrieve data. - - + + + &reftitle.returnvalues; + + PDOStatement::fetchSingle returns the first column + in the next row of a result set as a string value. + + + + There is no way to return the second or subsequent columns from a row + if you use this method to retrieve data. + + + + + + + &reftitle.examples; + Return first column of the next row ]]> - - &example.outputs; - + &example.outputs; + - + + + + + + &reftitle.seealso; + + + PDO::query + PDOStatement::fetch + PDOStatement::fetchAll + PDOStatement::prepare + PDOStatement::setFetchMode + +