mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Updating mysqli: set_charset (#844)
* default was confusing * Simplify examples * It's character set * Remove duplication
This commit is contained in:
parent
de9c65c91f
commit
a3365c7546
1 changed files with 11 additions and 31 deletions
|
@ -4,7 +4,7 @@
|
|||
<refnamediv>
|
||||
<refname>mysqli::set_charset</refname>
|
||||
<refname>mysqli_set_charset</refname>
|
||||
<refpurpose>Sets the default client character set</refpurpose>
|
||||
<refpurpose>Sets the client character set</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
|
@ -21,7 +21,7 @@
|
|||
<methodparam><type>string</type><parameter>charset</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
Sets the default character set to be used when sending data from and to
|
||||
Sets the character set to be used when sending data from and to
|
||||
the database server.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<term><parameter>charset</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The charset to be set as default.
|
||||
The desired character set.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -58,52 +58,32 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
|
||||
|
||||
/* check connection */
|
||||
if (mysqli_connect_errno()) {
|
||||
printf("Connect failed: %s\n", mysqli_connect_error());
|
||||
exit();
|
||||
}
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
|
||||
|
||||
printf("Initial character set: %s\n", $mysqli->character_set_name());
|
||||
|
||||
/* change character set to utf8mb4 */
|
||||
if (!$mysqli->set_charset("utf8mb4")) {
|
||||
printf("Error loading character set utf8mb4: %s\n", $mysqli->error);
|
||||
exit();
|
||||
} else {
|
||||
printf("Current character set: %s\n", $mysqli->character_set_name());
|
||||
}
|
||||
$mysqli->set_charset("utf8mb4");
|
||||
|
||||
$mysqli->close();
|
||||
?>
|
||||
printf("Current character set: %s\n", $mysqli->character_set_name());
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>&style.procedural;</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
|
||||
|
||||
/* check connection */
|
||||
if (mysqli_connect_errno()) {
|
||||
printf("Connect failed: %s\n", mysqli_connect_error());
|
||||
exit();
|
||||
}
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
|
||||
|
||||
printf("Initial character set: %s\n", mysqli_character_set_name($link));
|
||||
|
||||
/* change character set to utf8mb4 */
|
||||
if (!mysqli_set_charset($link, "utf8mb4")) {
|
||||
printf("Error loading character set utf8mb4: %s\n", mysqli_error($link));
|
||||
exit();
|
||||
} else {
|
||||
printf("Current character set: %s\n", mysqli_character_set_name($link));
|
||||
}
|
||||
mysqli_set_charset($link, "utf8mb4");
|
||||
|
||||
mysqli_close($link);
|
||||
?>
|
||||
printf("Current character set: %s\n", mysqli_character_set_name($link));
|
||||
]]>
|
||||
</programlisting>
|
||||
&examples.outputs.similar;
|
||||
|
|
Loading…
Reference in a new issue