reference/mysqli/mysqli/set-charset.xml
63b99082ef83eade08151f8cb528246fded81db9
...
...
@@ -4,24 +4,24 @@
4
4
<refnamediv>
5
5
<refname>mysqli::set_charset</refname>
6
6
<refname>mysqli_set_charset</refname>
7
-
<refpurpose>Sets the default client character set</refpurpose>
7
+
<refpurpose>Sets the client character set</refpurpose>
8
8
</refnamediv>
9
9

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::set_charset</methodname>
13
+
<methodsynopsis role="mysqli">
14
+
<modifier>public</modifier> <type>bool</type><methodname>mysqli::set_charset</methodname>
15
15
<methodparam><type>string</type><parameter>charset</parameter></methodparam>
16
16
</methodsynopsis>
17
17
<para>&style.procedural;</para>
18
18
<methodsynopsis>
19
19
<type>bool</type><methodname>mysqli_set_charset</methodname>
20
-
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
20
+
<methodparam><type>mysqli</type><parameter>mysql</parameter></methodparam>
21
21
<methodparam><type>string</type><parameter>charset</parameter></methodparam>
22
22
</methodsynopsis>
23
23
<para>
24
-
Sets the default character set to be used when sending data from and to
24
+
Sets the character set to be used when sending data from and to
25
25
the database server.
26
26
</para>
27
27
</refsect1>
...
...
@@ -35,7 +35,7 @@
35
35
<term><parameter>charset</parameter></term>
36
36
<listitem>
37
37
<para>
38
-
The charset to be set as default.
38
+
The desired character set.
39
39
</para>
40
40
</listitem>
41
41
</varlistentry>
...
...
@@ -50,22 +50,9 @@
50
50
</para>
51
51
</refsect1>
52
52

53
-
<refsect1 role="notes">
54
-
&reftitle.notes;
55
-
<note>
56
-
<para>
57
-
To use this function on a Windows platform you need MySQL client library
58
-
version 4.1.11 or above (for MySQL 5.0 you need 5.0.6 or above).
59
-
</para>
60
-
</note>
61
-
<note>
62
-
<para>
63
-
This is the preferred way to change the charset. Using
64
-
<function>mysqli_query</function> to set it (such as <literal>SET NAMES utf8</literal>)
65
-
is not recommended. See the <link linkend="mysqlinfo.concepts.charset">MySQL character set concepts</link>
66
-
section for more information.
67
-
</para>
68
-
</note>
53
+
<refsect1 role="errors">
54
+
&reftitle.errors;
55
+
&mysqli.conditionalexception;
69
56
</refsect1>
70
57

71
58
<refsect1 role="examples">
...
...
@@ -76,64 +63,62 @@
76
63
<programlisting role="php">
77
64
<![CDATA[
78
65
<?php
79
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
80
66

81
-
/* check connection */
82
-
if (mysqli_connect_errno()) {
83
-
printf("Connect failed: %s\n", mysqli_connect_error());
84
-
exit();
85
-
}
67
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
68
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
86
69

87
70
printf("Initial character set: %s\n", $mysqli->character_set_name());
88
71

89
-
/* change character set to utf8 */
90
-
if (!$mysqli->set_charset("utf8")) {
91
-
printf("Error loading character set utf8: %s\n", $mysqli->error);
92
-
exit();
93
-
} else {
94
-
printf("Current character set: %s\n", $mysqli->character_set_name());
95
-
}
72
+
/* change character set to utf8mb4 */
73
+
$mysqli->set_charset("utf8mb4");
96
74

97
-
$mysqli->close();
98
-
?>
75
+
printf("Current character set: %s\n", $mysqli->character_set_name());
99
76
]]>
100
77
</programlisting>
101
78
<para>&style.procedural;</para>
102
79
<programlisting role="php">
103
80
<![CDATA[
104
81
<?php
105
-
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
106
82

107
-
/* check connection */
108
-
if (mysqli_connect_errno()) {
109
-
printf("Connect failed: %s\n", mysqli_connect_error());
110
-
exit();
111
-
}
83
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
84
+
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
112
85

113
86
printf("Initial character set: %s\n", mysqli_character_set_name($link));
114
87

115
-
/* change character set to utf8 */
116
-
if (!mysqli_set_charset($link, "utf8")) {
117
-
printf("Error loading character set utf8: %s\n", mysqli_error($link));
118
-
exit();
119
-
} else {
120
-
printf("Current character set: %s\n", mysqli_character_set_name($link));
121
-
}
88
+
/* change character set to utf8mb4 */
89
+
mysqli_set_charset($link, "utf8mb4");
122
90

123
-
mysqli_close($link);
124
-
?>
91
+
printf("Current character set: %s\n", mysqli_character_set_name($link));
125
92
]]>
126
93
</programlisting>
127
94
&examples.outputs.similar;
128
95
<screen>
129
96
<![CDATA[
130
97
Initial character set: latin1
131
-
Current character set: utf8
98
+
Current character set: utf8mb4
132
99
]]>
133
100
</screen>
134
101
</example>
135
102
</refsect1>
136
103

104
+
<refsect1 role="notes">
105
+
&reftitle.notes;
106
+
<note>
107
+
<para>
108
+
To use this function on a Windows platform you need MySQL client library
109
+
version 4.1.11 or above (for MySQL 5.0 you need 5.0.6 or above).
110
+
</para>
111
+
</note>
112
+
<note>
113
+
<para>
114
+
This is the preferred way to change the charset. Using
115
+
<function>mysqli_query</function> to set it (such as <literal>SET NAMES utf8</literal>)
116
+
is not recommended. See the <link linkend="mysqlinfo.concepts.charset">MySQL character set concepts</link>
117
+
section for more information.
118
+
</para>
119
+
</note>
120
+
</refsect1>
121
+

137
122
<refsect1 role="seealso">
138
123
&reftitle.seealso;
139
124
<para>
...
...
@@ -147,7 +132,6 @@ Current character set: utf8
147
132
</refsect1>
148
133

149
134
</refentry>
150
-

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