Example of how to solve mysql5's write and read garbled characters
The code is as follows:
Require ("adodb/adodb. inc. php ");
$ Conn = newadoconnection ('mysql ');
$ 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 I have changed 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 use the following command to modify the character set of the database:
Alter database da_name default character set 'charset '.
The client sends data in gbk format. the following configurations can be used:
SET character_set_client = 'gbk'
SET character_set_connection = 'gbk'
SET character_set_results = 'gbk'
This configuration is equivalent to set names 'gbk '.
Perform operations on the database you just created
Mysql> use test;
Database changed
Mysql> insert into mysqlcode values (null, 'php hobby ');
ERROR 1406 (22001): Data too long for column 'content' at row 1
If the character set is not specified as gbk, an error occurs 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 hobby ');
Query OK, 1 row affected (0.00 sec)
Inserted successfully
Mysql> select * from mysqlcode;
+ ---- + ----------- +
| Id | content |
+ ---- + ----------- +
| 1 | php hobbies |
+ ---- + ----------- +
1 row in set (0.00 sec)
Garbled characters are also displayed when the character set gbk is not specified.
Mysql> select * from mysqlcode;
+ ---- + --------- +
| Id | content |
+ ---- + --------- +
| 1 | php ??? |
+ ---- + --------- +
1 row in set (0.00 sec)