From 65a76681a944aedf7dbd43b4f5ab0355d217c006 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Mon, 24 Jan 2005 03:11:02 +0000 Subject: [PATCH] Document constants, bindColumn, and lastInsertID. Correct minor errors in prepare and fetch. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@178071 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/pdo/constants.xml | 247 ++++++++++++++++-- reference/pdo/functions/PDO-lastInsertId.xml | 53 +++- reference/pdo/functions/PDO-prepare.xml | 77 +++++- .../pdo/functions/PDOStatement-bindColumn.xml | 130 ++++++++- .../pdo/functions/PDOStatement-fetch.xml | 5 +- 5 files changed, 468 insertions(+), 44 deletions(-) diff --git a/reference/pdo/constants.xml b/reference/pdo/constants.xml index 3eb500ec18..e5a9d14fb2 100644 --- a/reference/pdo/constants.xml +++ b/reference/pdo/constants.xml @@ -1,5 +1,5 @@ - +
&reftitle.constants; @@ -12,7 +12,7 @@ - + Represents the SQL NULL data type. @@ -23,7 +23,7 @@ - + Represents the SQL INTEGER data type. @@ -34,7 +34,7 @@ - + Represents the SQL CHAR, VARCHAR, or other string data type. @@ -45,7 +45,7 @@ - + Represents the SQL large object data type. @@ -67,7 +67,9 @@ - + Specifies that the fetch method shall return each row as an object with + variable names that correspond to the column names returned in the result + set. PDO_FETCH_LAZY creates the object variable names as they are accessed. @@ -78,7 +80,8 @@ - + Specifies that the fetch method shall return each row as an array indexed + by column name as returned in the corresponding result set. @@ -89,7 +92,9 @@ - + Specifies that the fetch method shall return each row as an array indexed + by column number as returned in the corresponding result set, starting at + column 0. @@ -100,7 +105,9 @@ - + Specifies that the fetch method shall return each row as an array indexed + by both column name and number as returned in the corresponding result set, + starting at column 0. @@ -109,6 +116,54 @@ PDO_FETCH_OBJ (integer) + + + Specifies that the fetch method shall return each row as an object with + property names that correspond to the column names returned in the result + set. + + + + + + PDO_FETCH_BOUND + (integer) + + + + Specifies that the fetch method shall return TRUE and assign the values of + the columns in the result set to the PHP variables to which they were + bound with the PDOStatement::bindParam() method. + + + + + + PDO_FETCH_COLUMN + (integer) + + + + + + + + + + PDO_FETCH_CLASS + (integer) + + + + + + + + + + PDO_FETCH_INTO + (integer) + @@ -126,17 +181,6 @@ - - - PDO_ATTR_SCROLL - (integer) - - - - - - - PDO_ATTR_PREFETCH @@ -219,6 +263,51 @@ PDO_ATTR_CASE (integer) + + + Force column names to a specific case specified by the PDO_CASE_* + constants. + + + + + + PDO_ATTR_CURSOR_NAME + (integer) + + + + + + + + + + PDO_ATTR_CURSOR + (integer) + + + + + + + + + + PDO_ATTR_ORACLE_NULLS + (integer) + + + + + + + + + + PDO_ATTR_PERSISTENT + (integer) + @@ -265,7 +354,7 @@ - + Leave column names as returned by the database driver. @@ -275,8 +364,8 @@ (integer) - - + + Force column names to lower case. @@ -287,18 +376,101 @@ - + Force column names to upper case. - PDO_ERR_NONE + PDO_FETCH_ORI_NEXT (integer) - + Fetch the next row in the result set. Valid only for scrollable cursors. + + + + + + PDO_FETCH_ORI_PRIOR + (integer) + + + + Fetch the previous row in the result set. Valid only for scrollable + cursors. + + + + + + PDO_FETCH_ORI_FIRST + (integer) + + + + Fetch the first row in the result set. Valid only for scrollable cursors. + + + + + + PDO_FETCH_ORI_LAST + (integer) + + + + Fetch the last row in the result set. Valid only for scrollable cursors. + + + + + + PDO_FETCH_ORI_ABS + (integer) + + + + Fetch the requested row by row number from the result set. Valid only + for scrollable cursors. + + + + + + PDO_FETCH_ORI_REL + (integer) + + + + Fetch the requested row by relative position from the current position + of the cursor in the result set. Valid only for scrollable cursors. + + + + + + PDO_CURSOR_FWDONLY + (integer) + + + + Create a PDOStatement object with a forward-only cursor. This may improve + the performance of your application but restricts your PROStatement object + to fetching one row at a time from the result set in a forward direction. + + + + + + PDO_CURSOR_SCROLL + (integer) + + + + Create a PDOStatement object with a scrollable cursor. Pass the + PDO_FETCH_ORI_* constants to control the rows fetched from the result set. @@ -401,6 +573,29 @@ + + + PDO_ERR_NO_PERM + (integer) + + + + + + + + + + PDO_ERR_NONE + (string) + + + + Corresponds to SQLSTATE '00000', meaning that the SQL statement was + successfully issued with no errors or warnings. + + +
diff --git a/reference/pdo/functions/PDO-lastInsertId.xml b/reference/pdo/functions/PDO-lastInsertId.xml index 486aa214fe..ed842dd23e 100644 --- a/reference/pdo/functions/PDO-lastInsertId.xml +++ b/reference/pdo/functions/PDO-lastInsertId.xml @@ -1,27 +1,70 @@ - + PDO::lastInsertId - Returns the number id of rows that we affected by the last call to PDO::exec() + Returns the ID of the last inserted row - + Description intPDO::lastInsertId - &warn.undocumented.func; + &warn.experimental.func; - Not always meaningful. + Due to differences between database server implmenetations, this method + may not always return a meaningful result. + + + &reftitle.returnvalues; + + Returns an integer representing the row ID of the last row that was + inserted into the database. If the PDO driver does not support this + capability, PDO::lastInsertID issues a PDOWarning + exception. + + + + + + @@ -13,16 +13,50 @@ PDOStatementPDO::prepare stringstatement - intoptions &warn.experimental.func; - Prepares an SQL statement to be executed by the statement-handle - PDO::execute method. The SQL statement can contain zero - or more named (:name) or question mark (?) parameter markers. + Prepares an SQL statement to be executed by the + PDOStatement::execute method. The SQL statement can + contain zero or more named (:name) or question mark (?) parameter markers + for which real values will be substituted when the statement is executed. - Prepare and execute an SQL statement + + Calling PDO::prepare and PDOStatement::execute + for statements that will be issued multiple times with different parameter + values optimizes the performance of your application and helps prevent SQL + injection attacks. + + + + &reftitle.parameters; + + + + statement + + + This must be a valid SQL statement for the target database server. + + + + + + + + + &reftitle.returnvalues; + + If the database server successfully prepares the statement, + PDO::prepare returns a PDOStatement object. + + + + + &reftitle.examples; + + Prepare an SQL statement with named parameters prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $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('SELECT name, colour, calories + FROM fruit + WHERE calories < ? AND colour = ?'); +$sth->execute(array(150, 'red')); +$red = $sth->fetchAll(); +$sth->execute(array(175, 'yellow')); +$yellow = $sth->fetchAll(); +?> +]]> + + + + + + &reftitle.seealso; + + + PDO::exec + PDO::query + PDOStatement::execute + + diff --git a/reference/pdo/functions/PDOStatement-bindColumn.xml b/reference/pdo/functions/PDOStatement-bindColumn.xml index e789813f5c..4edbebaf0f 100644 --- a/reference/pdo/functions/PDOStatement-bindColumn.xml +++ b/reference/pdo/functions/PDOStatement-bindColumn.xml @@ -1,5 +1,5 @@ - + @@ -16,18 +16,138 @@ mixedparam inttype intmaxlen - mixeddriverdata + mixeddriver_options - &warn.undocumented.func; + &warn.experimental.func; On each row fetch param will contain the value of the corresponding column. column is the 1-based - offset of the column, or the column name. For portability, don't call - this before PDO::execute. + offset of the column, or the column name. For maximum portability, do not + call this function before calling + PDOStatement::execute. + + + &reftitle.parameters; + + + + column + + + Number of the column (1-indexed) in the result set. + + + + + param + + + Name of the PHP variable to which the column will be bound. + + + + + type + + + Data type of the parameter, specified by the PDO_PARAM_* constants. + + + + + maxlen + + + Maximum length of the parameter. + + + + + driver_options + + + + + + + + + + + + &reftitle.examples; + + + Binding result set output to PHP variables + + Binding columns in the result set to PHP variables is an effective + way to make the data contained in each row immediately available to + your application. The following example demonstrates how PDO allows + you to bind and retrieve columns with a variety of options and with + intelligent defaults. + + + prepare($sql); + $stmt->execute(); + + /* Bind by column number with an explicit data type & length */ + $stmt->bindColumn(1, $name, PDO_PARAM_STR, 64); + + /* Bind by column number with default data type & length */ + $stmt->bindColumn(2, $colour); + + /* Bind by column name with default data type & length */ + $stmt->bindColumn('CALORIES', $cals); + + while ($row = $stmt->fetch(PDO_FETCH_BOUND)) { + $data = $name . "\t" . $colour . "\t" . $cals . "\n"; + print $data; + } + } + catch (PDOException $e) { + print $e->getMessage(); + } +} +readData($dbh); +?> + ]]> + + &example.outputs; + + + + + + + + + &reftitle.seealso; + + + PDOStatement::execute + PDOStatement::fetch + PDOStatement::fetchAll + PDOStatement::fetchSingle + + + + + @@ -33,7 +33,8 @@ 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 + they were bound with the PDOStatement::bindParam + method PDO_FETCH_LAZY: combines