mirror of
https://github.com/php/doc-en.git
synced 2026-03-23 23:32:18 +01:00
Various amendements to follow-up on GH-4936 (#4980)
This commit is contained in:
committed by
GitHub
parent
cd8b964b85
commit
7e384b24f7
@@ -2,10 +2,10 @@
|
||||
<section xmlns="http://docbook.org/ns/docbook" xml:id="pdo.constants.fetch-modes">
|
||||
<title>Fetch Modes</title>
|
||||
|
||||
<para>
|
||||
<simpara>
|
||||
See <link linkend="pdo.constants.cursors">cursor constants</link> for the
|
||||
<literal>PDO::FETCH_ORI_*</literal> cursor constants.
|
||||
</para>
|
||||
</simpara>
|
||||
|
||||
<section xml:id="pdo.fetch-modes.basic" annotations="chunk:false">
|
||||
<title>Basic Fetch Modes</title>
|
||||
@@ -81,7 +81,7 @@
|
||||
</entry>
|
||||
<entry>
|
||||
Use a function to create the return value.
|
||||
(<function>PDOStatement::fetchAll</function> only)
|
||||
(<methodname>PDOStatement::fetchAll</methodname> only)
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
@@ -108,10 +108,10 @@
|
||||
<section xml:id="pdo.fetch-modes.class-flags" annotations="chunk:false">
|
||||
<title>PDO::FETCH_CLASS options</title>
|
||||
|
||||
<para>
|
||||
<simpara>
|
||||
These modes are used to implement options when using
|
||||
<constant>PDO::FETCH_CLASS</constant>.
|
||||
</para>
|
||||
</simpara>
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
@@ -154,10 +154,10 @@
|
||||
<section xml:id="pdo.fetch-modes.single" annotations="chunk:false">
|
||||
<title>Single Result Modes</title>
|
||||
|
||||
<para>
|
||||
<simpara>
|
||||
The following modes cannot be used with
|
||||
<function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
<methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
@@ -200,14 +200,14 @@
|
||||
|
||||
<section xml:id="pdo.fetch-modes.grouped" annotations="chunk:false">
|
||||
<title>
|
||||
Special Behavior Flags for <function>PDOStatement::fetchAll</function>
|
||||
Special Behavior Flags for <methodname>PDOStatement::fetchAll</methodname>
|
||||
</title>
|
||||
|
||||
<para>
|
||||
<simpara>
|
||||
The following special modes for multiple results only work with
|
||||
<function>PDOStatement::fetchAll</function> and do not work with some other
|
||||
<methodname>PDOStatement::fetchAll</methodname> and do not work with some other
|
||||
fetch modes. Check the full documentation for details.
|
||||
</para>
|
||||
</simpara>
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
@@ -241,23 +241,23 @@
|
||||
|
||||
<section xml:id="pdo.fetch-modes.duplicate-names" annotations="chunk:false">
|
||||
<title>Handling of Duplicated Column Names</title>
|
||||
<para>
|
||||
<simpara>
|
||||
It's possible for results to contain multiple columns that use the same name.
|
||||
For example, when joining 2 tables that both contain a column with the same
|
||||
name.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
Because PHP structures such as arrays and objects don't support multiple keys
|
||||
or properties that use the same name, the returned array or object will
|
||||
contain only 1 of the values using the same name.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
Which value is returned for a given duplicated name should be considered
|
||||
undefined.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
To avoid this issue, explicitly name columns using an alias. For example:
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="sql">
|
||||
<![CDATA[
|
||||
@@ -268,48 +268,48 @@ JOIN table2 ON table1.table2id = table2.id
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
<para>
|
||||
<simpara>
|
||||
See also <constant>PDO::FETCH_NAMED</constant>,
|
||||
<constant>PDO::ATTR_FETCH_TABLE_NAMES</constant> and
|
||||
<constant>PDO::ATTR_FETCH_CATALOG_NAMES</constant>.
|
||||
</para>
|
||||
</simpara>
|
||||
</section>
|
||||
|
||||
<section xml:id="pdo.fetch-modes.default" annotations="chunk:false">
|
||||
<title>Setting the Default Fetch Mode</title>
|
||||
<para>
|
||||
You can set the default fetch mode for all queries using
|
||||
<simpara>
|
||||
It is possible to set default fetch mode for all queries using
|
||||
<constant>PDO::ATTR_DEFAULT_FETCH_MODE</constant> with
|
||||
<function>PDO::__construct</function> or
|
||||
<function>PDO::setAttribute</function>.
|
||||
</para>
|
||||
<para>
|
||||
You can set the default fetch mode for a specific statement using
|
||||
<function>PDOStatement::setFetchMode</function>. This affects reuse as a
|
||||
prepared statement and iteration (using
|
||||
<link linkend="control-structures.foreach">foreach</link>).
|
||||
</para>
|
||||
<methodname>PDO::__construct</methodname> or
|
||||
<methodname>PDO::setAttribute</methodname>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
The default fetch mode for a specific statement can be set using
|
||||
<methodname>PDOStatement::setFetchMode</methodname>.
|
||||
This affects reuse as a prepared statement and iteration (using
|
||||
&foreach;).
|
||||
</simpara>
|
||||
<caution>
|
||||
<para>
|
||||
<function>PDOStatement::setAttribute</function> cannot be used to set the
|
||||
<simpara>
|
||||
<methodname>PDOStatement::setAttribute</methodname> cannot be used to set the
|
||||
default fetch mode. It only accepts driver specific attributes and silently
|
||||
ignores attributes that are not recognized.
|
||||
</para>
|
||||
</simpara>
|
||||
</caution>
|
||||
</section>
|
||||
|
||||
<section xml:id="pdo.constants.fetch-default" annotations="chunk:false">
|
||||
<title>PDO::FETCH_DEFAULT (<type>int</type>)</title>
|
||||
<para>
|
||||
Available since PHP 8.0.7.
|
||||
</para>
|
||||
<para>
|
||||
<simpara>
|
||||
Available as of PHP 8.0.7.
|
||||
</simpara>
|
||||
<simpara>
|
||||
This is a special value that uses the current default fetch mode for a
|
||||
<classname>PDOStatement</classname>. It's specifically useful as the default
|
||||
value for method parameters when extending
|
||||
<classname>PDOStatement</classname> for use with
|
||||
<constant>PDO::ATTR_STATEMENT_CLASS</constant>.
|
||||
</para>
|
||||
</simpara>
|
||||
<para>
|
||||
This value cannot be used with
|
||||
<constant>PDO::ATTR_DEFAULT_FETCH_MODE</constant>.
|
||||
@@ -318,10 +318,10 @@ JOIN table2 ON table1.table2id = table2.id
|
||||
|
||||
<section xml:id="pdo.constants.fetch-assoc" annotations="chunk:false">
|
||||
<title>PDO::FETCH_ASSOC (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_ASSOC</constant> returns an array indexed by column name
|
||||
only.
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -347,31 +347,31 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-both" annotations="chunk:false">
|
||||
<title>PDO::FETCH_BOTH (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
This is the default fetch mode.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_BOTH</constant> returns an array indexed by both column
|
||||
number and name. This means that every returned value is duplicated for each
|
||||
result row.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
The column number starts at 0 and is determined by the result column order in
|
||||
the query, not (for example) the order columns are defined in the table.
|
||||
</para>
|
||||
</simpara>
|
||||
<note>
|
||||
<para>
|
||||
<simpara>
|
||||
Using the numeric column index is not recommended as this may change when
|
||||
the query is changed, or when the table schema is changed when using
|
||||
<literal>SELECT *</literal>.
|
||||
</para>
|
||||
</simpara>
|
||||
</note>
|
||||
<note>
|
||||
<para>
|
||||
<simpara>
|
||||
The number of entries indexed by name may not match the number of entries
|
||||
indexed by number in cases where multiple returned columns use the same
|
||||
name.
|
||||
</para>
|
||||
</simpara>
|
||||
</note>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
@@ -401,20 +401,20 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-named" annotations="chunk:false">
|
||||
<title>PDO::FETCH_NAMED (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_NAMED</constant> returns results in the same format as
|
||||
<constant>PDO::FETCH_ASSOC</constant> except that where multiple columns use
|
||||
the same name, all values are returned as a list.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
For more information on handling of duplicated column names and alternatives,
|
||||
see the <link linkend="pdo.fetch-modes.duplicate-names">handling of
|
||||
duplicated names section</link> above.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
The order in which duplicated values are returned should be considered
|
||||
undefined. There's no way to tell where each value came from.
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -450,17 +450,17 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-num" annotations="chunk:false">
|
||||
<title>PDO::FETCH_NUM (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_NUM</constant> returns an array indexed by column number
|
||||
only. The column number starts at 0 and is determined by the result column order in
|
||||
the query, not (for example) the order columns are defined in the table.
|
||||
</para>
|
||||
</simpara>
|
||||
<note>
|
||||
<para>
|
||||
<simpara>
|
||||
Using the numeric column index is not recommended as this may change when
|
||||
the query is changed, or when the table schema is changed when using
|
||||
<literal>SELECT *</literal>.
|
||||
</para>
|
||||
</simpara>
|
||||
</note>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
@@ -487,16 +487,16 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-column" annotations="chunk:false">
|
||||
<title>PDO::FETCH_COLUMN (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_COLUMN</constant> returns values from a single column.
|
||||
Use the second argument for <function>PDOStatement::setFetchMode</function>
|
||||
or <function>PDOStatement::fetchAll</function> to specify which column is
|
||||
Use the second argument for <methodname>PDOStatement::setFetchMode</methodname>
|
||||
or <methodname>PDOStatement::fetchAll</methodname> to specify which column is
|
||||
returned.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
If the specified column does not exist a <classname>ValueError</classname>
|
||||
will be thrown.
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -533,16 +533,16 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-key-pair" annotations="chunk:false">
|
||||
<title>PDO::FETCH_KEY_PAIR (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_KEY_PAIR</constant> returns pairs of values, indexed by
|
||||
the first column. The results must contain only 2 columns. This fetch mode
|
||||
only makes sense with <function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
only makes sense with <methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
<note>
|
||||
<para>
|
||||
<simpara>
|
||||
If the first column is not unique, values will be lost. Which value(s) are
|
||||
lost should be considered undefined.
|
||||
</para>
|
||||
</simpara>
|
||||
</note>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
@@ -569,21 +569,22 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-func" annotations="chunk:false">
|
||||
<title>PDO::FETCH_FUNC (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
Specify a function to create the returned value. This mode can only be used
|
||||
with <function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
<para>
|
||||
The function receives the values as parameters. There's no way to retrieve
|
||||
the column name a given value was associated with. You must make sure the
|
||||
column order in the query matches that expected by the function.
|
||||
</para>
|
||||
with <methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
The function receives the values as parameters.
|
||||
There's no way to retrieve the column name a given value was associated with.
|
||||
It is crucial to ensure that the column order in the query matches the
|
||||
order of parameters of the function.
|
||||
</simpara>
|
||||
<note>
|
||||
<para>
|
||||
<simpara>
|
||||
The effects of <constant>PDO::FETCH_GROUP</constant> and
|
||||
<constant>PDO::FETCH_UNIQUE</constant> are applied to results before the
|
||||
function is called.
|
||||
</para>
|
||||
</simpara>
|
||||
</note>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
@@ -641,14 +642,14 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-obj" annotations="chunk:false">
|
||||
<title>PDO::FETCH_OBJ (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_OBJ</constant> returns a <classname>stdClass</classname>
|
||||
object.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>PDOStatement::fetchObject</function> and
|
||||
</simpara>
|
||||
<simpara>
|
||||
See also <methodname>PDOStatement::fetchObject</methodname> and
|
||||
<constant>PDO::FETCH_CLASS</constant>.
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -674,18 +675,18 @@ stdClass Object
|
||||
|
||||
<section xml:id="pdo.constants.fetch-class" annotations="chunk:false">
|
||||
<title>PDO::FETCH_CLASS (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
Returns an object of a specified class. For additional behaviors see the
|
||||
<link linkend="pdo.fetch-modes.class-flags">option flags</link>.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
If a property does not exist with the name of a returned column, it will be
|
||||
dynamically declared. This behavior is deprecated and will cause an error
|
||||
from PHP 9.0.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>PDOStatement::fetchObject</function>.
|
||||
</para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
See also <methodname>PDOStatement::fetchObject</methodname>.
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -738,19 +739,19 @@ object(TestEntity)#3 (4) {
|
||||
|
||||
<section xml:id="pdo.constants.fetch-classtype" annotations="chunk:false">
|
||||
<title>PDO::FETCH_CLASSTYPE (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
This fetch mode can only be used combined with
|
||||
<constant>PDO::FETCH_CLASS</constant> (and
|
||||
<link linkend="pdo.fetch-modes.class-flags">its other options</link>).
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
When this fetch mode is used, PDO will use the first returned column as the
|
||||
name of the class to return.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
If the specified class cannot be found, a <classname>stdClass</classname>
|
||||
object will be returned, without warning or error.
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -803,15 +804,15 @@ object(TestEntity)#3 (4) {
|
||||
|
||||
<section xml:id="pdo.constants.fetch-props-late" annotations="chunk:false">
|
||||
<title>PDO::FETCH_PROPS_LATE (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
This fetch mode can only be used combined with
|
||||
<constant>PDO::FETCH_CLASS</constant> (and
|
||||
<link linkend="pdo.fetch-modes.class-flags">its other options</link>).
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
When this fetch mode is used, the constructor will be called before the
|
||||
properties are set.
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -870,25 +871,25 @@ object(TestEntity)#3 (4) {
|
||||
Relying on this feature is highly discouraged.
|
||||
</simpara>
|
||||
</warning>
|
||||
<para>
|
||||
<simpara>
|
||||
This fetch mode can only be used combined with
|
||||
<constant>PDO::FETCH_CLASS</constant> (and
|
||||
<link linkend="pdo.fetch-modes.class-flags">its other options</link>).
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
When this fetch mode is used, the specified class must be
|
||||
<interfacename>Serializable</interfacename>.
|
||||
</para>
|
||||
</simpara>
|
||||
<caution>
|
||||
<para>
|
||||
<simpara>
|
||||
This feature does not support a string that contains a complete serialized
|
||||
object (with <function>serialize</function>).
|
||||
</para>
|
||||
</simpara>
|
||||
</caution>
|
||||
<caution>
|
||||
<para>
|
||||
<simpara>
|
||||
This fetch mode does not call the constructor.
|
||||
</para>
|
||||
</simpara>
|
||||
</caution>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
@@ -983,20 +984,20 @@ object(TestEntity)#5 (4) {
|
||||
|
||||
<section xml:id="pdo.constants.fetch-bound" annotations="chunk:false">
|
||||
<title>PDO::FETCH_BOUND (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
This fetch mode cannot be used with
|
||||
<function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
<para>
|
||||
<methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
This fetch mode does not directly return a result, but binds values to
|
||||
variables specified with <function>PDOStatement::bindColumn</function>. The
|
||||
variables specified with <methodname>PDOStatement::bindColumn</methodname>. The
|
||||
called fetch method returns &true;.
|
||||
</para>
|
||||
</simpara>
|
||||
<note>
|
||||
<para>
|
||||
<simpara>
|
||||
When using prepared statements, to work correctly, variables must be bound
|
||||
after the query is executed.
|
||||
</para>
|
||||
</simpara>
|
||||
</note>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -1036,29 +1037,29 @@ while ($stmt->fetch(\PDO::FETCH_BOUND)) {
|
||||
|
||||
<section xml:id="pdo.constants.fetch-into" annotations="chunk:false">
|
||||
<title>PDO::FETCH_INTO (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
This fetch mode cannot be used with
|
||||
<function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
<para>
|
||||
<methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
This fetch mode updates properties in the specified object. The object is
|
||||
returned on success.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
If a property does not exist with the name of a returned column, it will be
|
||||
dynamically declared. This behavior is deprecated and will cause an error
|
||||
from PHP 9.0.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
Properties must be <literal>public</literal> and cannot be
|
||||
<literal>readonly</literal>.
|
||||
</para>
|
||||
</simpara>
|
||||
<caution>
|
||||
<para>
|
||||
<simpara>
|
||||
There's no way to change the object to be updated without using
|
||||
<function>PDOStatement::setFetchMode</function> between retrieving each
|
||||
<methodname>PDOStatement::setFetchMode</methodname> between retrieving each
|
||||
record.
|
||||
</para>
|
||||
</simpara>
|
||||
</caution>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
@@ -1103,34 +1104,34 @@ object(TestEntity)#3 (4) {
|
||||
|
||||
<section xml:id="pdo.constants.fetch-lazy" annotations="chunk:false">
|
||||
<title>PDO::FETCH_LAZY (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
This fetch mode cannot be used with
|
||||
<function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
<para>
|
||||
<methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
This fetch mode returns a <classname>PDORow</classname> object which provides
|
||||
both array- and object-like access to values (i.e. combines the behavior of
|
||||
<constant>PDO::FETCH_BOTH</constant> and
|
||||
<constant>PDO::FETCH_OBJ</constant>), retrieved in a lazy manner.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
This can provide memory efficient access (on the PHP side) to unbuffered
|
||||
results on the database server. Whether PDO uses client-side buffering for
|
||||
results depends on the database-specific driver used (and its configuration).
|
||||
</para>
|
||||
</simpara>
|
||||
<caution>
|
||||
<para>
|
||||
<simpara>
|
||||
<classname>PDORow</classname> will return <literal>NULL</literal> without
|
||||
any error or warning when accessing properties or keys that are not defined.
|
||||
This can make errors such as typos or queries not returning expected data
|
||||
harder to spot and debug.
|
||||
</para>
|
||||
</simpara>
|
||||
</caution>
|
||||
<caution>
|
||||
<para>
|
||||
<simpara>
|
||||
The returned <classname>PDORow</classname> object is updated each time a
|
||||
result is retrieved.
|
||||
</para>
|
||||
</simpara>
|
||||
</caution>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -1164,26 +1165,26 @@ ID: 105
|
||||
|
||||
<section xml:id="pdo.constants.fetch-group" annotations="chunk:false">
|
||||
<title>PDO::FETCH_GROUP (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_GROUP</constant> returns lists of associative arrays,
|
||||
indexed by a (non-unique) column. This fetch mode only works with
|
||||
<function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
<para>
|
||||
<methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
When combined with <constant>PDO::FETCH_UNIQUE</constant>, both modes will
|
||||
use the same column, rendering the combination of these modes useless.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
This fetch should be combined with one of
|
||||
<constant>PDO::FETCH_ASSOC</constant>, <constant>PDO::FETCH_BOTH</constant>,
|
||||
<constant>PDO::FETCH_NAMED</constant>, <constant>PDO::FETCH_NUM</constant>,
|
||||
<constant>PDO::FETCH_COLUMN</constant> or
|
||||
<constant>PDO::FETCH_FUNC</constant>.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
If no fetch mode from the above list is given, the current default fetch mode
|
||||
for the <classname>PDOStatement</classname> will be used.
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -1241,11 +1242,11 @@ Array
|
||||
]]>
|
||||
</screen>
|
||||
</informalexample>
|
||||
<para>
|
||||
In the above example you'll note that the first column is omitted from the
|
||||
<simpara>
|
||||
In the above example one should note that the first column is omitted from the
|
||||
array for each row, only available as the key. It can be included by
|
||||
repeating the column, as in the following example:
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
@@ -1312,43 +1313,43 @@ Array
|
||||
|
||||
<section xml:id="pdo.constants.fetch-unique" annotations="chunk:false">
|
||||
<title>PDO::FETCH_UNIQUE (<type>int</type>)</title>
|
||||
<para>
|
||||
<simpara>
|
||||
<constant>PDO::FETCH_UNIQUE</constant> uses the first column to index records,
|
||||
returning 1 record per index value. This fetch mode only works with
|
||||
<function>PDOStatement::fetchAll</function>.
|
||||
</para>
|
||||
<para>
|
||||
<methodname>PDOStatement::fetchAll</methodname>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
When combined with <constant>PDO::FETCH_GROUP</constant>, both modes will use
|
||||
the same column, rendering the combination of these modes useless.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
This fetch should be combined with one of
|
||||
<constant>PDO::FETCH_ASSOC</constant>, <constant>PDO::FETCH_BOTH</constant>,
|
||||
<constant>PDO::FETCH_NAMED</constant>, <constant>PDO::FETCH_NUM</constant>,
|
||||
<constant>PDO::FETCH_COLUMN</constant> or
|
||||
<constant>PDO::FETCH_FUNC</constant>.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
If no fetch mode from the above list is given, the current default fetch mode
|
||||
for the <classname>PDOStatement</classname> will be used.
|
||||
</para>
|
||||
<para>
|
||||
</simpara>
|
||||
<simpara>
|
||||
When used with a column that is known to be unique (such as record ID), this
|
||||
mode provides the ability to quickly return results indexed by that value.
|
||||
</para>
|
||||
</simpara>
|
||||
<note>
|
||||
<para>
|
||||
<simpara>
|
||||
If the first column is not unique, values will be lost. Which value(s) are
|
||||
lost should be considered undefined.
|
||||
</para>
|
||||
</simpara>
|
||||
</note>
|
||||
<caution>
|
||||
<para>
|
||||
<simpara>
|
||||
Filtering records should be done in SQL where possible. The database will
|
||||
use indexes to optimize this process and return only the required records.
|
||||
Selecting more records than required from the database may significantly
|
||||
increase memory usage and query time for larger result sets.
|
||||
</para>
|
||||
</simpara>
|
||||
</caution>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
@@ -1386,11 +1387,11 @@ Array
|
||||
]]>
|
||||
</screen>
|
||||
</informalexample>
|
||||
<para>
|
||||
In the above example you'll note that the first column is omitted from the
|
||||
<simpara>
|
||||
In the above example one should note that the first column is omitted from the
|
||||
array for each row, only available as the key. It can be included by
|
||||
repeating the column, as in the following example:
|
||||
</para>
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
<section xml:id="pdo.constants.cursors" annotations="chunk:false">
|
||||
<title>Cursors</title>
|
||||
|
||||
<para>
|
||||
<simpara>
|
||||
See also <constant>PDO::ATTR_CURSOR_NAME</constant>.
|
||||
</para>
|
||||
</simpara>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry xml:id="pdo.constants.fetch-ori-next">
|
||||
@@ -104,8 +104,9 @@
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Create a <classname>PDOStatement</classname> object with a scrollable cursor. Pass the
|
||||
<literal>PDO::FETCH_ORI_*</literal> constants to control the rows fetched from the result set.
|
||||
Create a <classname>PDOStatement</classname> object with a scrollable cursor.
|
||||
Pass the <constant>PDO::FETCH_ORI_<replaceable>*</replaceable></constant>
|
||||
constants to control the rows fetched from the result set.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -169,7 +170,7 @@
|
||||
Flag to denote a string uses the national character set.
|
||||
</simpara>
|
||||
<simpara>
|
||||
Available since PHP 7.2.0
|
||||
Available as of PHP 7.2.0
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -183,7 +184,7 @@
|
||||
Flag to denote a string uses the regular character set.
|
||||
</simpara>
|
||||
<simpara>
|
||||
Available since PHP 7.2.0
|
||||
Available as of PHP 7.2.0
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -217,8 +218,8 @@
|
||||
<listitem>
|
||||
<simpara>
|
||||
Specifies that the parameter is an INOUT parameter for a stored
|
||||
procedure. You must bitwise-OR this value with an explicit
|
||||
PDO::PARAM_* data type.
|
||||
procedure. This constant must be bitwise-ORed with one of the
|
||||
<constant>PDO::PARAM_<replaceable>*</replaceable></constant> constants.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -241,8 +242,8 @@
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Setting the prefetch size allows you to balance speed against memory
|
||||
usage for your application. Not all database/driver combinations support
|
||||
Setting the prefetch size allows balancing speed against memory
|
||||
usage for an application. Not all database/driver combinations support
|
||||
setting of the prefetch size. A larger prefetch size results in
|
||||
increased performance at the cost of higher memory usage.
|
||||
</simpara>
|
||||
@@ -325,7 +326,8 @@
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Force column names to a specific case specified by the <literal>PDO::CASE_*</literal>
|
||||
Force column names to a specific case specified by the
|
||||
<constant>PDO::CASE_<replaceable>*</replaceable></constant>
|
||||
constants.
|
||||
</simpara>
|
||||
</listitem>
|
||||
@@ -350,10 +352,10 @@
|
||||
<listitem>
|
||||
<simpara>
|
||||
Selects the cursor type. PDO currently supports either
|
||||
<constant>PDO::CURSOR_FWDONLY</constant> and
|
||||
<constant>PDO::CURSOR_SCROLL</constant>. Stick with
|
||||
<constant>PDO::CURSOR_FWDONLY</constant> unless you know that you need a
|
||||
scrollable cursor.
|
||||
<constant>PDO::CURSOR_FWDONLY</constant> or
|
||||
<constant>PDO::CURSOR_SCROLL</constant>.
|
||||
Unless one has a need for scrollable cursors, one should use the
|
||||
<constant>PDO::CURSOR_FWDONLY</constant> cursor mode.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -367,8 +369,8 @@
|
||||
<simpara>
|
||||
Returns the name of the driver.
|
||||
</simpara>
|
||||
<para>
|
||||
<example><title>using <constant>PDO::ATTR_DRIVER_NAME</constant></title>
|
||||
<example>
|
||||
<title>using <constant>PDO::ATTR_DRIVER_NAME</constant></title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
@@ -378,8 +380,7 @@
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</example>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry xml:id="pdo.constants.attr-oracle-nulls">
|
||||
@@ -427,7 +428,7 @@
|
||||
Prepend the containing catalog name to each column name returned in the
|
||||
result set. The catalog name and column name are separated by a decimal
|
||||
(.) character. Support of this attribute is at the driver level; it may
|
||||
not be supported by your driver.
|
||||
not be supported by the driver in use.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -440,8 +441,8 @@
|
||||
<simpara>
|
||||
Prepend the containing table name to each column name returned in the
|
||||
result set. The table name and column name are separated by a decimal (.)
|
||||
character. Support of this attribute is at the driver level; it may not
|
||||
be supported by your driver.
|
||||
character. Support of this attribute is at the driver level; it may
|
||||
not be supported by the driver in use.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -502,7 +503,7 @@
|
||||
and <constant>PDO::PARAM_STR_CHAR</constant>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
Available since PHP 7.2.0.
|
||||
Available as of PHP 7.2.0.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -513,8 +514,9 @@
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Do not raise an error or exception if an error occurs. The developer is
|
||||
expected to explicitly check for errors. This is the default mode.
|
||||
Do not raise an error or exception if an error occurs.
|
||||
The developer is expected to explicitly check for errors.
|
||||
Prior to PHP 8.0.0, this was the default mode.
|
||||
See <link linkend="pdo.error-handling">Errors and error handling</link>
|
||||
for more information about this attribute.
|
||||
</simpara>
|
||||
@@ -541,6 +543,7 @@
|
||||
<listitem>
|
||||
<simpara>
|
||||
Throw a <classname>PDOException</classname> if an error occurs.
|
||||
This is the default mode as of PHP 8.0.0.
|
||||
See <link linkend="pdo.error-handling">Errors and error handling</link>
|
||||
for more information about this attribute.
|
||||
</simpara>
|
||||
@@ -619,12 +622,14 @@
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Corresponds to SQLSTATE '00000', meaning that the SQL statement was
|
||||
successfully issued with no errors or warnings. This constant is for
|
||||
your convenience when checking <methodname>PDO::errorCode</methodname> or
|
||||
Corresponds to SQLSTATE <literal>'00000'</literal>, meaning that the SQL
|
||||
statement was successfully issued with no errors or warnings.
|
||||
This constant is a convenience constant to help when checking
|
||||
<methodname>PDO::errorCode</methodname> or
|
||||
<methodname>PDOStatement::errorCode</methodname> to determine if an error
|
||||
occurred. You will usually know if this is the case by examining the
|
||||
return code from the method that raised the error condition anyway.
|
||||
occurred.
|
||||
This is usually known by examining the return code from the method
|
||||
that raised the error condition anyway.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
Reference in New Issue
Block a user