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) { $rc->fields["cc"]); $rc->movenext(); } ?>
當然我們也可以透過以下指令修改資料庫的字元集 alter database da_name default character set 'charset'. 客戶端以 gbk格式傳送 ,可採用下述設定: SET character_set_client='gb' SET character_set_results='gbk' 這個配置就等價於 SET NAMES 'gbk'。 現在對剛剛建立的資料庫操作 mysql> use test; Database changed mysql> insert into mysqlcode values(null,'php愛好者'); ERROR2 : Data too long for column 'content' at row 1 沒有指定字元集為gbk,插入時發生錯誤 mysql> set names 'gbk'; Query 0. 🎜>指定字元集為 gbk mysql> insert into mysqlcode values(null,'php愛好者'); Query OK, 1 row affected (0.00 sec)