这两天用PHP ADODB做数据库访问层,发现数据添加到进数据库后,读进读出都是对的,但是用phpMyAdmin打开时,就乱得一踏。前两天试着结果,在Google下找了半天没找到。刚才终于找到解决办法了,贴出来,希望以后出现同样问题的人们可以更容易找到答案。
具体做法是:
我是参考这儿的,可以过去看看原文,写得很清楚。
在/adodb/drivers/adodb-mysql.inc.php 中,修改以下两个函数:
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (ADODB_PHPVER >= 0x4300)
$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
$this->forceNewConnect,$this->clientFlags);
else if (ADODB_PHPVER >= 0x4200)
$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
$this->forceNewConnect);
else
$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
+ @mysql_query("SET NAMES 'utf8'", $this->_connectionID);
if ($argDatabasename) return $this->SelectDB($argDatabasename);
return true;
}
|
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (ADODB_PHPVER >= 0x4300)
$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
else
$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
+ @mysql_query("SET NAMES 'utf8'", $this->_connectionID);
if ($this->autoRollback) $this->RollbackTrans();
if ($argDatabasename) return $this->SelectDB($argDatabasename);
return true;
}
|
阅读(1440) | 评论(2) | 转发(0) |