mysql query error mysql5 write and read garbled solution

WBOY
Release: 2016-07-29 08:35:16
Original
1187 people have browsed it

The example I wrote

Copy the code The code is as follows:

require("adodb/adodb.inc.php");
$c
$conn->connect("localhost"," root","2027205","bh38") or die("Connection failed");
$conn->execute("set names gb2312");
$conn->execute("INSERT INTO `vv` (`cc`) VALUES ('I don’t know if it will work if I change the encoding');") or die("Error");
$rc=$conn->execute("select * from vv");
while (!$rc->EOF)
{
echo($rc->fields["cc"]);
$rc->movenext();
}
?>


Of course we can also pass The following command modifies the character set of the database
alter database da_name default character set 'charset'.
The client sends it in gbk format. You can use the following configuration:
SET character_set_client='gbk'
SET character_set_c
SET character_set_results='gbk'
This configuration is equivalent to SET NAMES 'gbk'.
Now operate the database you just created
mysql> use test;
Database changed
mysql> insert into mysqlcode values(null,'php enthusiast');
ERROR 1406 (22001): Data too long for column 'content' at row 1
The character set is not specified as gbk, an error occurred during insertion
mysql> set names 'gbk';
Query OK, 0 rows affected (0.02 sec)
The specified character set is gbk
mysql> insert into mysqlcode values(null,' php lovers');
Query OK, 1 row affected (0.00 sec)
Insertion successful
mysql> select * from mysqlcode;
+----+-----------+
| id | content |
+----+-----------+
| 1 | PHP lover |
+----+-----------+
1 row in set (0.00 sec)
When reading without specifying the character set gbk, garbled characters will also appear, as follows
mysql> select * from mysqlcode;
+----+----------+
| id | content |
+----+---------+
| 1 | php??? |
+----+---------+
1 row in set (0.00 sec)

The above introduces the solution to mysql query error when writing and reading garbled characters in mysql5, including the content of mysql query error. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!