pdo语句,引号存储为?

kfgdxczn  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(215)

所以,我对pdo非常陌生,我尝试了一些东西并进行了实践,碰巧当我尝试用下面的代码插入一些特殊字符时,我对我的数据库发生了什么感到非常困惑:

<?php
    $post_cat     = 4;
    $post_title   = "TESTING";
    $post_author  = "Test";
    $post_image   = "test_image.png";
    $post_content = "“Luo Changan, I grant you five breaths’ time. Show me whether you’re actually such a ‘person’ as you say, or a dog that would ‘beg to surrender!’”";
    $post_tags    = "novel, mga, chinese novel";
    $ID_post_stat = 2;

    $pdo = new PDO("mysql:charset=utf8mb4;hostname=localhost;dbname=cms;", "root", "");
    $stmt = $pdo->prepare('INSERT INTO posts (ID_post_category, post_title, post_author, post_image, post_content, post_tags, ID_post_status) VALUES (?, ?, ?, ?, ?, ?, ?)');

    $stmt->bindParam(1, $post_cat);
    $stmt->bindParam(2, $post_title);
    $stmt->bindParam(3, $post_author);
    $stmt->bindParam(4, $post_image);
    $stmt->bindParam(5, $post_content);
    $stmt->bindParam(6, $post_tags);
    $stmt->bindParam(7, $ID_post_stat);
    $stmt->execute();

    /* data stored:   

    +------------------+------------+-------------+----------------+-----------------------------------------+---------------------------+----------------+
    | ID_post_category | post_title | post_author | post_image     | post_content                            | post_tags                 | ID_post_status |
    +------------------+------------+-------------+----------------+-----------------------------------------+---------------------------+----------------+
    |                4 | TESTING    | Test        | test_image.png | ?Luo Changan, I grant you five breaths? | novel, mga, chinese novel |              2 |
    |                  |            |             |                | time. Show me whether you?re actually   |                           |                |
    |                  |            |             |                | such a ?person? as you say, or a dog    |                           |                |
    |                  |            |             |                | that would ?beg to surrender!??         |                           |                |
    +------------------+------------+-------------+----------------+-----------------------------------------+---------------------------+----------------+
    */
?>

我在寻找为什么这个字符(“”)没有被存储在数据库中,而是被替换为(?)的答案,我试图将表和列更改为utf8,因为我已经阅读了社区的一些答案,但似乎没有什么区别,它的工作很好(áéíóú) 不过。提前谢谢!
正如madhur bhaiya所建议的,我再次尝试检查它的charset,甚至aplied charset=utf8mb4 对我的pdo dsn有什么帮助 utf8_decode 或者 utf8_encode 对于每一个字符串,它确实已经全部设置为utf8,所以我猜这种字符(比如 curl 引号)不支持这个字符集,那么我该如何解决这个问题呢?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题