Home > Backend Development > PHP Tutorial > Mysql5 writing and reading garbled code solution_PHP tutorial

Mysql5 writing and reading garbled code solution_PHP tutorial

WBOY
Release: 2016-07-21 15:59:56
Original
762 people have browsed it

The example I wrote

Copy code 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 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 do too You can modify the character set of the database through the following command
alter database da_name default character set 'charset'.
The client sends it in gbk format, and you can use the following configuration:
SET character_set_client='gbk'
SET character_set_connection='gbk'
SET character_set_results='gbk'
This configuration is equivalent to SET NAMES 'gbk'.
Now operate the database 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 hobby |
+----+-----------+
1 row in set (0.00 sec)
In When the character set gbk is not specified, garbled characters will appear when reading, as follows
mysql> select * from mysqlcode;
+----+---------+
| id | content |
+----+---------+
| 1 | php??? |
+----+---------+
1 row in set (0.00 sec)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317240.htmlTechArticleThe example copy code I wrote is as follows: ? require("adodb/adodb.inc.php"); $ conn=newadoconnection('mysql'); $conn-connect("localhost","root","2027205","bh38")ordie("Connection failed...
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