reference/mysqli/mysqli/character-set-name.xml
035c126c0393fe154bac46e2c3c489ebadce48a5
...
...
@@ -4,23 +4,23 @@
4
4
<refnamediv>
5
5
<refname>mysqli::character_set_name</refname>
6
6
<refname>mysqli_character_set_name</refname>
7
-
<refpurpose>Returns the default character set for the database connection</refpurpose>
7
+
<refpurpose>Returns the current character set of the database connection</refpurpose>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<para>Object oriented style (method):</para>
13
-
<methodsynopsis>
14
-
<type>string</type><methodname>mysqli::character_set_name</methodname>
15
-
<void />
16
-
</methodsynopsis>
17
-
<para>Procedural style:</para>
12
+
<para>&style.oop;</para>
13
+
<methodsynopsis role="mysqli">
14
+
<modifier>public</modifier> <type>string</type><methodname>mysqli::character_set_name</methodname>
15
+
<void/>
16
+
</methodsynopsis>
17
+
<para>&style.procedural;</para>
18
18
<methodsynopsis>
19
19
<type>string</type><methodname>mysqli_character_set_name</methodname>
20
-
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
20
+
<methodparam><type>mysqli</type><parameter>mysql</parameter></methodparam>
21
21
</methodsynopsis>
22
22
<para>
23
-
Returns the current character set for the database connection.
23
+
Returns the current character set of the database connection.
24
24
</para>
25
25
</refsect1>
26
26

...
...
@@ -35,78 +35,65 @@
35
35

36
36
<refsect1 role="returnvalues">
37
37
&reftitle.returnvalues;
38
-
<para>The default character set for the current connection</para>
38
+
<para>The current character set of the connection</para>
39
39
</refsect1>
40
40

41
41
<refsect1 role="examples">
42
42
&reftitle.examples;
43
43
<example>
44
-
<title>Object oriented style</title>
44
+
<title><methodname>mysqli::character_set_name</methodname> example</title>
45
+
<para>&style.oop;</para>
45
46
<programlisting role="php">
46
47
<![CDATA[
47
48
<?php
48
-
/* Open a connection */
49
+

50
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
49
51
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
50
52

51
-
/* check connection */
52
-
if (mysqli_connect_errno()) {
53
-
printf("Connect failed: %s\n", mysqli_connect_error());
54
-
exit();
55
-
}
53
+
/* Set the default character set */
54
+
$mysqli->set_charset('utf8mb4');
56
55

57
56
/* Print current character set */
58
57
$charset = $mysqli->character_set_name();
59
-
printf ("Current character set is %s\n", $charset);
60
-

61
-
$mysqli->close();
62
-
?>
58
+
printf("Current character set is %s\n", $charset);
63
59
]]>
64
-
</programlisting>
65
-
</example>
66
-
<example>
67
-
<title>Procedural style</title>
60
+
</programlisting>
61
+
<para>&style.procedural;</para>
68
62
<programlisting role="php">
69
63
<![CDATA[
70
64
<?php
71
-
/* Open a connection */
72
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
73
65

74
-
/* check connection */
75
-
if (!$link) {
76
-
printf("Connect failed: %s\n", mysqli_connect_error());
77
-
exit();
78
-
}
66
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
67
+
$mysqli = mysqli_connect("localhost", "my_user", "my_password", "world");
79
68

80
-
/* Print current character set */
81
-
$charset = mysqli_character_set_name($link);
82
-
printf ("Current character set is %s\n",$charset);
69
+
/* Set the default character set */
70
+
mysqli_set_charset($mysqli, 'utf8mb4');
83
71

84
-
/* close connection */
85
-
mysqli_close($link);
86
-
?>
72
+
/* Print current character set */
73
+
$charset = mysqli_character_set_name($mysqli);
74
+
printf("Current character set is %s\n", $charset);
87
75
]]>
88
76
</programlisting>
89
-
</example>
90
-
&example.outputs;
91
-
<screen>
77
+
&examples.outputs;
78
+
<screen>
92
79
<![CDATA[
93
-
Current character set is latin1_swedish_ci
80
+
Current character set is utf8mb4
94
81
]]>
95
-
</screen>
82
+
</screen>
83
+
</example>
96
84
</refsect1>
97
85

98
86
<refsect1 role="seealso">
99
87
&reftitle.seealso;
100
88
<para>
101
89
<simplelist>
102
-
<member><function>mysqli_client_encoding</function></member>
90
+
<member><function>mysqli_set_charset</function></member>
103
91
<member><function>mysqli_real_escape_string</function></member>
104
92
</simplelist>
105
93
</para>
106
94
</refsect1>
107
95

108
96
</refentry>
109
-

110
97
<!-- Keep this comment at the end of the file
111
98
Local variables:
112
99
mode: sgml
113
100