PDO PHP希伯来语不起作用

时间:2016-12-11 12:22:21

标签: php mysql sql pdo hebrew

嘿,我尝试了一个使用pdo和php的代码,在本地wamp服务器上它完美运行并显示希伯来语和英语但是当我把代码放在网络上时它会向我显示希伯来语,就像这个'''''这样奇怪的符号•'''''''''''''''''''''' wamp sql表和web sql表都设置为utf8_general_ci

这是我的代码:

    <?php
    $db = new PDO('mysql:host=127.0.0.1;dbname=android;charset=utf8', 'root', '');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $db->query('SELECT * FROM sample');
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

$out = '';
if (is_array($results) && count($results) > 0) 
{
  foreach ($results as $sqlRow) 
  {
    $out .= $sqlRow['id']."|||".$sqlRow['name']."|||";
  }

  $out = substr($out, 0, -3);
}
echo $out;
?>

2 个答案:

答案 0 :(得分:0)

问题可能不在MySQL中,而是在Web服务器上的PHP中。尝试在php.ini中设置此属性:

default_charset = "utf-8"

详细了解此媒体资源here

答案 1 :(得分:0)

change to this row
for me it is helped
This after you set the table utf-8

$ conn = new PDO(“mysql:host = localhost; dbname = $ database; charset = UTF8”,“root”,“”,array(PDO :: MYSQL_ATTR_INIT_COMMAND =&gt;“SET NAMES utf8”))或死(“没有连接”);     $ conn-&gt; setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION);