0

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

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

我的数据库和表是 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 添加它一样

4

1 回答 1

0

谢谢解决方案是在连接代码之后执行这个

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

于 2013-04-22T09:22:12.590 回答