我在数据库中有utf-8-general-ci ..并且在希伯来语langugae中插入数据..现在当我检索数据时它显示我的字符串像?????? .. 数据库连接是这样的..
function __construct($strHost='', $strDB='', $strUser='', $strPass='')
{
try{
if($strHost != ''){$this->strHost = $strHost;}
if($strDB != ''){$this->strDB = $strDB;}
if($strUser != ''){$this->strUser = $strUser;}
if($strPass != ''){$this->strPass = $strPass;}
$this->objDB = new PDO("mysql:host=".$this->strHost.";port=3306;dbname=".$this->strDB,$this->strUser, $this->strPass, array( PDO::ATTR_PERSISTENT => true));
if($this->objDB)
{
return $this->objDB;
}
else
{
echo "Database Connection Failed.";die;
}
}
catch(Exception $objException)
{
echo $objException->getMessage();exit;
}
}
任何人都可以帮忙吗?
答案 0 :(得分:1)
在PDO连接中添加utf8
$this->objDB = new PDO("mysql:host=".$this->strHost.";port=3306;dbname=".$this->strDB, $this->strUser, $this->strPass,
array( PDO::ATTR_PERSISTENT => true,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));