From 243267c3018866bd78f5f328ec2882285acdfd45 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Fri, 19 Nov 2004 22:21:35 +0000 Subject: [PATCH] Add examples, elaborate slightly on PDOStatement::fetchAll. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@173068 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../pdo/functions/PDOStatement-fetch.xml | 85 ++++++++++++++++--- .../pdo/functions/PDOStatement-fetchAll.xml | 61 ++++++++++--- 2 files changed, 125 insertions(+), 21 deletions(-) diff --git a/reference/pdo/functions/PDOStatement-fetch.xml b/reference/pdo/functions/PDOStatement-fetch.xml index 6b1e1e3fd3..a0dcc6944c 100644 --- a/reference/pdo/functions/PDOStatement-fetch.xml +++ b/reference/pdo/functions/PDOStatement-fetch.xml @@ -1,5 +1,5 @@ - + @@ -22,10 +22,6 @@ fetch_style can be one of the following values: - - PDO_FETCH_NUM: returns an array indexed by column - number as returned in your result set, starting at column 0 - PDO_FETCH_ASSOC: returns an array indexed by column name as returned in your result set @@ -35,9 +31,9 @@ both column name and column number as returned in your result set - PDO_FETCH_OBJ: returns an anonymous object with - property names that correspond to the column names 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 PDO::bindParam method PDO_FETCH_LAZY: combines @@ -45,13 +41,80 @@ creating the object variable names as they are accessed - 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 PDO::bindParam method + 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 + +fetch(PDO_FETCH_ASSOC); +print_r($result); +print("\n"); + +print("PDO_FETCH_BOTH: "); +print("Return next row as an array indexed by both column name and number\n"); +$result = $sth->fetch(PDO_FETCH_BOTH); +print_r($result); +print("\n"); + +print("PDO_FETCH_LAZY: "); +print("Return next row as an anonymous object with column names as properties\n"); +$result = $sth->fetch(PDO_FETCH_LAZY); +print_r($result); +print("\n"); + +print("PDO_FETCH_OBJ: "); +print("Return next row as an anonymous object with column names as properties\n"); +$result = $sth->fetch(PDO_FETCH_OBJ); +print $result->NAME; +print("\n"); +?> +]]> + + + &example.outputs; + + apple + [COLOUR] => red +) + +PDO_FETCH_BOTH: Return next row as an array indexed by both column name and number +Array +( + [NAME] => banana + [0] => banana + [COLOUR] => yellow + [1] => yellow +) + +PDO_FETCH_LAZY: Return next row as an anonymous object with column names as properties +PDORow Object +( + [NAME] => orange + [COLOUR] => orange +) + +PDO_FETCH_OBJ: Return next row as an anonymous object with column names as properties +kiwi +]]> + + diff --git a/reference/pdo/functions/PDOStatement-fetchAll.xml b/reference/pdo/functions/PDOStatement-fetchAll.xml index 9edf9712d0..7cbe943290 100644 --- a/reference/pdo/functions/PDOStatement-fetchAll.xml +++ b/reference/pdo/functions/PDOStatement-fetchAll.xml @@ -1,27 +1,68 @@ - + PDOStatement::fetchAll - Returns an array of all of the results + Returns an array containing all of the result set rows Description arrayPDOStatement::fetchAll - inthow + intfetch_style - &warn.undocumented.func; - - - how defaults to - PDO_FETCH_BOTH. - - + &warn.experimental.func; + + 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. + + + Fetch all remaining rows in a result set + +fetchAll(); +print_r($result); +?> +]]> + + &example.outputs; + + Array + ( + [NAME] => pear + [0] => pear + [COLOUR] => green + [1] => green + ) + + [1] => Array + ( + [NAME] => watermelon + [0] => watermelon + [COLOUR] => pink + [1] => pink + ) + +) +]]> + +