svn: /phpdoc/en/trunk/reference/ mysql/functions/mysql-set-charset.xml mysqli/mysqli/set-charset.xml mysqlinfo/concepts.xml
| From: | Philip Olson | Date: | Wed, 26 Aug 2015 04:32:39 +0000 |
| Subject: | svn: /phpdoc/en/trunk/reference/ mysql/functions/mysql-set-charset.xml mysqli/mysqli/set-charset.xml mysqlinfo/concepts.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13660@lists.php.net to get a copy of this message | ||
philip Wed, 26 Aug 2015 04:32:39 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=337633
Log:
Improved the MySQL character set documentation, a bit
Changed paths:
U phpdoc/en/trunk/reference/mysql/functions/mysql-set-charset.xml
U phpdoc/en/trunk/reference/mysqli/mysqli/set-charset.xml
U phpdoc/en/trunk/reference/mysqlinfo/concepts.xml
Modified: phpdoc/en/trunk/reference/mysql/functions/mysql-set-charset.xml
===================================================================
--- phpdoc/en/trunk/reference/mysql/functions/mysql-set-charset.xml 2015-08-26 04:31:05 UTC (rev
337632)
+++ phpdoc/en/trunk/reference/mysql/functions/mysql-set-charset.xml 2015-08-26 04:32:39 UTC (rev
337633)
@@ -73,9 +73,9 @@
&reftitle.seealso;
<para>
<simplelist>
- <member><function>mysql_client_encoding</function></member>
<member><link linkend="mysqlinfo.concepts.charset">Setting character sets
in MySQL</link></member>
<member><link xlink:href="&url.mysql.charsets;">List of character
sets that MySQL supports</link></member>
+ <member><function>mysql_client_encoding</function></member>
</simplelist>
</para>
</refsect1>
Modified: phpdoc/en/trunk/reference/mysqli/mysqli/set-charset.xml
===================================================================
--- phpdoc/en/trunk/reference/mysqli/mysqli/set-charset.xml 2015-08-26 04:31:05 UTC (rev 337632)
+++ phpdoc/en/trunk/reference/mysqli/mysqli/set-charset.xml 2015-08-26 04:32:39 UTC (rev 337633)
@@ -84,9 +84,12 @@
exit();
}
+printf("Initial character set: %s\n", $mysqli->character_set_name());
+
/* change character set to utf8 */
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
+ exit();
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
@@ -107,9 +110,12 @@
exit();
}
+printf("Initial character set: %s\n", mysqli_character_set_name($link));
+
/* change character set to utf8 */
if (!mysqli_set_charset($link, "utf8")) {
printf("Error loading character set utf8: %s\n", mysqli_error($link));
+ exit();
} else {
printf("Current character set: %s\n", mysqli_character_set_name($link));
}
@@ -118,9 +124,10 @@
?>
]]>
</programlisting>
- &examples.outputs;
+ &examples.outputs.similar;
<screen>
<![CDATA[
+Initial character set: latin1
Current character set: utf8
]]>
</screen>
@@ -133,6 +140,7 @@
<simplelist>
<member><function>mysqli_character_set_name</function></member>
<member><function>mysqli_real_escape_string</function></member>
+ <member><link linkend="mysqlinfo.concepts.charset">MySQL character set
concepts</link></member>
<member><link xlink:href="&url.mysql.charsets;">List of character
sets that MySQL supports</link></member>
</simplelist>
</para>
Modified: phpdoc/en/trunk/reference/mysqlinfo/concepts.xml
===================================================================
--- phpdoc/en/trunk/reference/mysqlinfo/concepts.xml 2015-08-26 04:31:05 UTC (rev 337632)
+++ phpdoc/en/trunk/reference/mysqlinfo/concepts.xml 2015-08-26 04:32:39 UTC (rev 337633)
@@ -145,15 +145,18 @@
$mysqli = new mysqli("localhost", "my_user", "my_password",
"world");
-// Will not affect $mysqli->real_escape_string();
+// Will NOT affect $mysqli->real_escape_string();
$mysqli->query("SET NAMES utf8");
-// Will not affect $mysqli->real_escape_string();
+// Will NOT affect $mysqli->real_escape_string();
$mysqli->query("SET CHARACTER SET utf8");
// But, this will affect $mysqli->real_escape_string();
$mysqli->set_charset('utf8');
+// But, this will NOT affect it (utf-8 vs utf8) -- don't use dashes here
+$mysqli->set_charset('utf-8');
+
?>
]]>
</programlisting>
@@ -163,21 +166,32 @@
Below are examples that demonstrate how to properly alter the character set at runtime
using each API.
</para>
+
+ <note>
+ <title>Possible UTF-8 confusion</title>
+ <para>
+ Because character set names in MySQL do not contain dashes, the string
+ "utf8" is valid in MySQL to set the character set to UTF-8. The string
+ "utf-8" is not valid, as using "utf-8" will fail to change the
+ character set.
+ </para>
+ </note>
<example>
<title>Setting the character set example: mysqli</title>
<programlisting role="php">
<![CDATA[
<?php
-
$mysqli = new mysqli("localhost", "my_user", "my_password",
"world");
+printf("Initial character set: %s\n", $mysqli->character_set_name());
+
if (!$mysqli->set_charset('utf8')) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
-} else {
- printf("Current character set: %s\n", $mysqli->character_set_name());
+ exit;
}
+echo "New character set information:\n";
print_r( $mysqli->get_charset() );
?>
@@ -204,17 +218,17 @@
<programlisting role="php">
<![CDATA[
<?php
-
$conn = mysql_connect("localhost", "my_user", "my_pass");
$db = mysql_select_db("world");
+echo 'Initial character set: ' . mysql_client_encoding($conn) . "\n";
+
if (!mysql_set_charset('utf8', $conn)) {
echo "Error: Unable to set the character set.\n";
exit;
}
echo 'Your current character set is: ' . mysql_client_encoding($conn);
-
?>
]]>
</programlisting>