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,70 +63,75 @@
76
63
<programlisting role="php">
77
64
<![CDATA[
78
65
<?php
66
+

67
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
79
68
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
80
69

81
-
/* check connection */
82
-
if (mysqli_connect_errno()) {
83
-
printf("Connect failed: %s\n", mysqli_connect_error());
84
-
exit();
85
-
}
86
-

87
-
/* change character set to utf8 */
88
-
if (!$mysqli->set_charset("utf8")) {
89
-
printf("Error loading character set utf8: %s\n", $mysqli->error);
90
-
} else {
91
-
printf("Current character set: %s\n", $mysqli->character_set_name());
92
-
}
93
-

94
-
$mysqli->close();
95
-
?>
70
+
printf("Initial character set: %s\n", $mysqli->character_set_name());
71
+

72
+
/* change character set to utf8mb4 */
73
+
$mysqli->set_charset("utf8mb4");
74
+

75
+
printf("Current character set: %s\n", $mysqli->character_set_name());
96
76
]]>
97
77
</programlisting>
98
78
<para>&style.procedural;</para>
99
79
<programlisting role="php">
100
80
<![CDATA[
101
81
<?php
82
+

83
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
102
84
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
103
85

104
-
/* check connection */
105
-
if (mysqli_connect_errno()) {
106
-
printf("Connect failed: %s\n", mysqli_connect_error());
107
-
exit();
108
-
}
109
-

110
-
/* change character set to utf8 */
111
-
if (!mysqli_set_charset($link, "utf8")) {
112
-
printf("Error loading character set utf8: %s\n", mysqli_error($link));
113
-
} else {
114
-
printf("Current character set: %s\n", mysqli_character_set_name($link));
115
-
}
116
-

117
-
mysqli_close($link);
118
-
?>
86
+
printf("Initial character set: %s\n", mysqli_character_set_name($link));
87
+

88
+
/* change character set to utf8mb4 */
89
+
mysqli_set_charset($link, "utf8mb4");
90
+

91
+
printf("Current character set: %s\n", mysqli_character_set_name($link));
119
92
]]>
120
93
</programlisting>
121
-
&examples.outputs;
94
+
&examples.outputs.similar;
122
95
<screen>
123
96
<![CDATA[
124
-
Current character set: utf8
97
+
Initial character set: latin1
98
+
Current character set: utf8mb4
125
99
]]>
126
100
</screen>
127
101
</example>
128
102
</refsect1>
129
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
+

130
122
<refsect1 role="seealso">
131
123
&reftitle.seealso;
132
124
<para>
133
125
<simplelist>
134
126
<member><function>mysqli_character_set_name</function></member>
135
127
<member><function>mysqli_real_escape_string</function></member>
128
+
<member><link linkend="mysqlinfo.concepts.charset">MySQL character set concepts</link></member>
136
129
<member><link xlink:href="&url.mysql.charsets;">List of character sets that MySQL supports</link></member>
137
130
</simplelist>
138
131
</para>
139
132
</refsect1>
140
133

141
134
</refentry>
142
-

143
135
<!-- Keep this comment at the end of the file
144
136
Local variables:
145
137
mode: sgml
146
138