reference/mysqli/mysqli/sqlstate.xml
d9de192baa45cdf33168eea8a45d14216def4395
...
...
@@ -10,11 +10,11 @@
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<fieldsynopsis><type>string</type><varname linkend="mysqli.sqlstate">mysqli->sqlstate</varname></fieldsynopsis>
13
+
<fieldsynopsis><type>string</type><varname linkend="mysqli.sqlstate">mysqli-&gt;sqlstate</varname></fieldsynopsis>
14
14
<para>&style.procedural;</para>
15
15
<methodsynopsis>
16
16
<type>string</type><methodname>mysqli_sqlstate</methodname>
17
-
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
17
+
<methodparam><type>mysqli</type><parameter>mysql</parameter></methodparam>
18
18
</methodsynopsis>
19
19
<para>
20
20
Returns a string containing the SQLSTATE error code for the last error.
...
...
@@ -50,47 +50,37 @@
50
50
<refsect1 role="examples">
51
51
&reftitle.examples;
52
52
<example>
53
-
<title><varname>$mysqli->sqlstate</varname> example</title>
53
+
<title><varname>$mysqli-&gt;sqlstate</varname> example</title>
54
54
<para>&style.oop;</para>
55
55
<programlisting role="php">
56
56
<![CDATA[
57
57
<?php
58
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
59
58

60
-
/* check connection */
61
-
if (mysqli_connect_errno()) {
62
-
printf("Connect failed: %s\n", mysqli_connect_error());
63
-
exit();
64
-
}
59
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
60
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
65
61

66
62
/* Table City already exists, so we should get an error */
67
-
if (!$mysqli->query("CREATE TABLE City (ID INT, Name VARCHAR(30))")) {
63
+
try {
64
+
$mysqli->query("CREATE TABLE City (ID INT, Name VARCHAR(30))");
65
+
} catch (mysqli_sql_exception) {
68
66
printf("Error - SQLSTATE %s.\n", $mysqli->sqlstate);
69
67
}
70
-

71
-
$mysqli->close();
72
-
?>
73
68
]]>
74
69
</programlisting>
75
70
<para>&style.procedural;</para>
76
71
<programlisting role="php">
77
72
<![CDATA[
78
73
<?php
79
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
80
74

81
-
/* check connection */
82
-
if (mysqli_connect_errno()) {
83
-
printf("Connect failed: %s\n", mysqli_connect_error());
84
-
exit();
85
-
}
75
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
76
+
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
86
77

87
78
/* Table City already exists, so we should get an error */
88
-
if (!mysqli_query($link, "CREATE TABLE City (ID INT, Name VARCHAR(30))")) {
79
+
try {
80
+
mysqli_query($link, "CREATE TABLE City (ID INT, Name VARCHAR(30))");
81
+
} catch (mysqli_sql_exception) {
89
82
printf("Error - SQLSTATE %s.\n", mysqli_sqlstate($link));
90
83
}
91
-

92
-
mysqli_close($link);
93
-
?>
94
84
]]>
95
85
</programlisting>
96
86
&examples.outputs;
...
...
@@ -113,7 +103,6 @@ Error - SQLSTATE 42S01.
113
103
</refsect1>
114
104

115
105
</refentry>
116
-

117
106
<!-- Keep this comment at the end of the file
118
107
Local variables:
119
108
mode: sgml
120
109