reference/pdo/connections.xml
d861a1bcea24f05e52e4938c1ecdf9d70326d7aa
...
...
@@ -36,28 +36,24 @@ $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
36
36
<?php
37
37
try {
38
38
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
39
-
foreach($dbh->query('SELECT * from FOO') as $row) {
40
-
print_r($row);
41
-
}
42
-
$dbh = null;
43
39
} catch (PDOException $e) {
44
-
print "Error!: " . $e->getMessage() . "<br/>";
45
-
die();
40
+
// attempt to retry the connection after some timeout for example
46
41
}
47
-
?>
48
42
]]>
49
43
</programlisting>
50
44
</example>
51
45
</para>
52
46
<warning>
53
47
<para>
54
-
If your application does not catch the exception thrown from the PDO
55
-
constructor, the default action taken by the zend engine is to terminate
56
-
the script and display a back trace. This back trace will likely reveal
57
-
the full database connection details, including the username and
58
-
password. It is your responsibility to catch this exception, either
59
-
explicitly (via a <literal>catch</literal> statement) or implicitly via
60
-
<function>set_exception_handler</function>.
48
+
Just like any other <link linkend="language.exceptions">exception</link>,
49
+
<classname>PDOException</classname> could be caught either explicitly, via
50
+
a &catch; statement, or implicitly via <function>set_exception_handler</function>.
51
+
Otherwise, the default behaviour of converting an uncaught exception to a
52
+
<constant>E_FATAL_ERROR</constant> will occur.
53
+
The fatal error will contain a backtrace that can leak connection details.
54
+
As such, the &php.ini; option
55
+
<link linkend="ini.display-errors"><literal>display_errors</literal></link>
56
+
should be set to <literal>0</literal> on a production server.
61
57
</para>
62
58
</warning>
63
59
<para>
...
...
@@ -73,7 +69,7 @@ try {
73
69
<simpara>
74
70
If there are still other references to this PDO instance (such as from a
75
71
PDOStatement instance, or from other variables referencing the same PDO
76
-
instance), these have to be removed also (for instance, by assigning NULL to
72
+
instance), these have to be removed also (for instance, by assigning &null; to
77
73
the variable that references the PDOStatement).
78
74
</simpara>
79
75
</note>
...
...
@@ -118,12 +114,19 @@ $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(
118
114
</programlisting>
119
115
</example>
120
116
</para>
117
+
<para>
118
+
The value of the <constant>PDO::ATTR_PERSISTENT</constant> option is converted
119
+
to &boolean; (enable/disable persistent connections), unless it is a non-numeric
120
+
&string;, in which case it allows to use multiple persistent connection pools.
121
+
This is useful if different connections use incompatible settings, for instance,
122
+
different values of <constant>PDO::MYSQL_ATTR_USE_BUFFERED_QUERY</constant>.
123
+
</para>
121
124
<note>
122
125
<para>
123
126
If you wish to use persistent connections, you must set
124
127
<constant>PDO::ATTR_PERSISTENT</constant> in the array of driver options
125
128
passed to the PDO constructor. If setting this attribute with
126
-
<function>PDO::setAttribute</function> after instantiation of the
129
+
<methodname>PDO::setAttribute</methodname> after instantiation of the
127
130
object, the driver will not use persistent connections.
128
131
</para>
129
132
</note>
130
133