I have utf-8-general-ci in database..and inserted data in hebrew langugae.. now when i retrieve data it displays me string like ??????.. database connection is like this..
我在数据库中有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;
}
}
can anyone help please ?
有人可以帮忙吗?
1 个解决方案
#1
1
Add utf8 in your PDO connection as
在您的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'"));
Read http://php.net/manual/en/pdo.construct.php
阅读http://php.net/manual/en/pdo.construct.php
#1
1
Add utf8 in your PDO connection as
在您的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'"));
Read http://php.net/manual/en/pdo.construct.php
阅读http://php.net/manual/en/pdo.construct.php