reference/mysqli/mysqli/select-db.xml
63b99082ef83eade08151f8cb528246fded81db9
...
...
@@ -10,15 +10,15 @@
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<methodsynopsis role="oop">
14
-
<type>bool</type><methodname>mysqli::select_db</methodname>
15
-
<methodparam><type>string</type><parameter>dbname</parameter></methodparam>
13
+
<methodsynopsis role="mysqli">
14
+
<modifier>public</modifier> <type>bool</type><methodname>mysqli::select_db</methodname>
15
+
<methodparam><type>string</type><parameter>database</parameter></methodparam>
16
16
</methodsynopsis>
17
17
<para>&style.procedural;</para>
18
18
<methodsynopsis>
19
19
<type>bool</type><methodname>mysqli_select_db</methodname>
20
-
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
21
-
<methodparam><type>string</type><parameter>dbname</parameter></methodparam>
20
+
<methodparam><type>mysqli</type><parameter>mysql</parameter></methodparam>
21
+
<methodparam><type>string</type><parameter>database</parameter></methodparam>
22
22
</methodsynopsis>
23
23
<para>
24
24
Selects the default database to be used when performing queries against
...
...
@@ -39,7 +39,7 @@
39
39
<variablelist>
40
40
&mysqli.link.description;
41
41
<varlistentry>
42
-
<term><parameter>dbname</parameter></term>
42
+
<term><parameter>database</parameter></term>
43
43
<listitem>
44
44
<para>
45
45
The database name.
...
...
@@ -57,6 +57,11 @@
57
57
</para>
58
58
</refsect1>
59
59

60
+
<refsect1 role="errors">
61
+
&reftitle.errors;
62
+
&mysqli.conditionalexception;
63
+
</refsect1>
64
+

60
65
<refsect1 role="examples">
61
66
&reftitle.examples;
62
67
<example>
...
...
@@ -65,66 +70,44 @@
65
70
<programlisting role="php">
66
71
<![CDATA[
67
72
<?php
68
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
69
73

70
-
/* check connection */
71
-
if (mysqli_connect_errno()) {
72
-
printf("Connect failed: %s\n", mysqli_connect_error());
73
-
exit();
74
-
}
74
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
75
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
75
76

76
-
/* return name of current default database */
77
-
if ($result = $mysqli->query("SELECT DATABASE()")) {
78
-
$row = $result->fetch_row();
79
-
printf("Default database is %s.\n", $row[0]);
80
-
$result->close();
81
-
}
77
+
/* get the name of the current default database */
78
+
$result = $mysqli->query("SELECT DATABASE()");
79
+
$row = $result->fetch_row();
80
+
printf("Default database is %s.\n", $row[0]);
82
81

83
-
/* change db to world db */
82
+
/* change default database to "world" */
84
83
$mysqli->select_db("world");
85
84

86
-
/* return name of current default database */
87
-
if ($result = $mysqli->query("SELECT DATABASE()")) {
88
-
$row = $result->fetch_row();
89
-
printf("Default database is %s.\n", $row[0]);
90
-
$result->close();
91
-
}
92
-

93
-
$mysqli->close();
94
-
?>
85
+
/* get the name of the current default database */
86
+
$result = $mysqli->query("SELECT DATABASE()");
87
+
$row = $result->fetch_row();
88
+
printf("Default database is %s.\n", $row[0]);
95
89
]]>
96
90
</programlisting>
97
91
<para>&style.procedural;</para>
98
92
<programlisting role="php">
99
93
<![CDATA[
100
94
<?php
101
-
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
102
95

103
-
/* check connection */
104
-
if (mysqli_connect_errno()) {
105
-
printf("Connect failed: %s\n", mysqli_connect_error());
106
-
exit();
107
-
}
96
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
97
+
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
108
98

109
-
/* return name of current default database */
110
-
if ($result = mysqli_query($link, "SELECT DATABASE()")) {
111
-
$row = mysqli_fetch_row($result);
112
-
printf("Default database is %s.\n", $row[0]);
113
-
mysqli_free_result($result);
114
-
}
99
+
/* get the name of the current default database */
100
+
$result = mysqli_query($link, "SELECT DATABASE()");
101
+
$row = mysqli_fetch_row($result);
102
+
printf("Default database is %s.\n", $row[0]);
115
103

116
-
/* change db to world db */
104
+
/* change default database to "world" */
117
105
mysqli_select_db($link, "world");
118
106

119
-
/* return name of current default database */
120
-
if ($result = mysqli_query($link, "SELECT DATABASE()")) {
121
-
$row = mysqli_fetch_row($result);
122
-
printf("Default database is %s.\n", $row[0]);
123
-
mysqli_free_result($result);
124
-
}
125
-

126
-
mysqli_close($link);
127
-
?>
107
+
/* get the name of the current default database */
108
+
$result = mysqli_query($link, "SELECT DATABASE()");
109
+
$row = mysqli_fetch_row($result);
110
+
printf("Default database is %s.\n", $row[0]);
128
111
]]>
129
112
</programlisting>
130
113
&examples.outputs;
...
...
@@ -148,7 +131,6 @@ Default database is world.
148
131
</refsect1>
149
132

150
133
</refentry>
151
-

152
134
<!-- Keep this comment at the end of the file
153
135
Local variables:
154
136
mode: sgml
155
137