我写的例子
复制代码 代码如下:
require(adodb/adodb.inc.php);
$conn=newadoconnection('mysql');
$conn->connect(localhost,root,2027205,bh38) or die(连接不成功);
$conn->execute(set names gb2312);
$conn->execute(insert into `vv` (`cc`) values ('换了个编码不知道行不行');) or die(错误);
$rc=$conn->execute(select * from vv);
while(!$rc->eof)
{
echo($rc->fields[cc]);
$rc->movenext();
}
?>
当然我们也可以通过如下指令修改数据库的字符集
alter database da_name default character set 'charset'.
客户端以 gbk格式发送 ,可以采用下述配置:
set character_set_client='gbk'
set character_set_connection='gbk'
set character_set_results='gbk'
这个配置就等价于 set names 'gbk'。
现在对刚才创建的数据库操作
mysql> use test;
database changed
mysql> insert into mysqlcode values(null,'php爱好者');
error 1406 (22001): data too long for column 'content' at row 1
没有指定字符集为gbk,插入时出错
mysql> set names 'gbk';
query ok, 0 rows affected (0.02 sec)
指定字符集为 gbk
mysql> insert into mysqlcode values(null,'php爱好者');
query ok, 1 row affected (0.00 sec)
插入成功
mysql> select * from mysqlcode;
+----+-----------+
| id | content |
+----+-----------+
| 1 | php爱好着 |
+----+-----------+
1 row in set (0.00 sec)
在没有指定字符集gbk时读取也会出现乱码,如下
mysql> select * from mysqlcode;
+----+---------+
| id | content |
+----+---------+
| 1 | php? |
+----+---------+
1 row in set (0.00 sec)
http://www.bkjia.com/phpjc/317240.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/317240.htmltecharticle我写的例子 复制代码 代码如下: ? require(adodb/adodb.inc.php); $conn=newadoconnection('mysql'); $conn-connect(localhost,root,2027205,bh38)ordie(连接不成功...