嘿,我尝试了一个使用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;
?>
答案 0 :(得分:0)
答案 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);