将unicode字符添加到数据库问题

时间:2013-04-22 09:07:44

标签: php encoding utf-8

你好iam真的在努力解决这个问题

我有一个脚本可以将阿拉伯字母插入数据库

我的数据库和表格是utf-unicode_ci

$title = make_safe($_POST['title']);
$author = make_safe($_POST['author']);
$category = make_safe($_POST['category']);
$meta = str_replace(array('-', ' ', '*'),",",make_safe($_POST['meta']));
if ($title == "" OR $author == "" OR $category == "")
{
    echo $lang['STORY_FIELDS_MUST_FILL'];
    echo "<META HTTP-EQUIV='refresh' CONTENT='2; URL= stories.php?action=add'>"; 
}
else 
{
    $stmt = $db->prepare ("INSERT INTO stories (title,author,category,meta,date)
    VALUES (:title,:author,:category,:meta)");
    $stmt->execute(array(':title' => $title,
                         ':author' => $author,
                         ':category' => $category,
                         ':meta' => $meta));
    echo "$lang[STORY_ADDED]";
    echo "<META HTTP-EQUIV='refresh' CONTENT='2; URL=" . $_SERVER['HTTP_REFERER'] . "'>";
}

添加文章时,这个php代码在phpmyadmin中显示如下

http://i.stack.imgur.com/bQMag.jpg

当我通过Phpmyadmin

插入值时

它显示这样,一切都很顺利

http://i.stack.imgur.com/ohmlv.jpg

如何通过php代码添加它以显示相同,例如从phpmyadmin

添加它

1 个答案:

答案 0 :(得分:0)

感谢解决方案在连接代码之后执行此

$ pdo-&gt; exec('SET NAMES \'utf8 \'COLLATE \'utf8_unicode_ci \'');