connect("localhost ","root","2027205","bh38") or die("Connection failed"); $conn->execute("set names gb2312"); $conn->execute("INSERT"/> connect("localhost ","root","2027205","bh38") or die("Connection failed"); $conn->execute("set names gb2312"); $conn->execute("INSERT">

Home  >  Article  >  Backend Development  >  mysql query error mysql5 write and read garbled solution

mysql query error mysql5 write and read garbled solution

WBOY
WBOYOriginal
2016-07-29 08:35:161208browse

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.

Statement:
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