本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

在 MySQL 中,如果字母有重音,查询结果 = null

发布于2023-09-20 21:19     阅读(1140)     评论(0)     点赞(11)     收藏(1)


这是我的查询;在我的数据库中,所有leanguage都设置为utf8_general;如果存在某些字符,此查询返回 null,不知道是否只有重音

require_once('db_connect.php');

$sql = "SELECT avwp_posts.id, cast(avwp_posts.post_content as char(200) ) AS post_content, cast(avwp_posts.post_title as char(60) ) AS post_title, avwp_posts.post_type, avwp_posts.post_date_gmt, avwp_users.display_name as nicename FROM avwp_posts JOIN avwp_users ON (avwp_posts.post_author=avwp_users.id) WHERE post_type='post' AND post_status='publish' ORDER BY post_date_gmt DESC";
$result = $con->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    $myArray[] = $row;
    echo $myArray['post_content'];

    }
}else {
    echo json_encode("NOTOK");
}

echo json_encode($myArray);

$con->close();

这是查询的结果

[{“id”:“74”,“post_content”:null,“post_title”:null,“post_type”:“post”,“post_date_gmt”:“2017-03-25 12:54:35”,“nicename” :"ridertest"},{"id":"72","post_content":null,"post_title":"wwwwwwwwwwwwwwwwwwwww","post_type":"post","post_date_gmt":"2017-03-25 12:33 :37","nicename":"ridertest"},{"id":"66","post_content":null,"post_title":"porova","post_type":"post","post_date_gmt":"2017 -03-25 12:30:06","nicename":"ridertest"},{"id":"64","post_content":“哟斯特TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT -03-25 12:28:50 "," Nicename ":"Ridertest"}, {" ID " :"56","post_content":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","post_title":"Prova Prova Prova Prova Prova Pro弗吉尼亚州Prova Prova Prova ","post_type":"post","post_date_gmt":"2017-03-25 11:34:13","nicename":"ridertest"},{"id":"52","post_content":null,"post_title":"Prova primo articolo, 蓝色 giallo rosso verde azzurro","post_type":"post","post_date_gmt":"2017-03-25 11 :14:46","nicename":"ridertest"},{"id":"1","post_content":null,"post_title":"Il Primo Articolo","post_type":"post","post_date_gmt ":"2011-07-05 12:19:18","nicename":"ridertest"}]"post_content":null,"post_title":"Il Primo Articolo","post_type":"post","post_date_gmt":"2011-07-05 12:19:18","nicename":"ridertest"}]"post_content":null,"post_title":"Il Primo Articolo","post_type":"post","post_date_gmt":"2011-07-05 12:19:18","nicename":"ridertest"}]

如果我使用 substring (char(200)) 得到没有重音的 char 部分,则返回一个值,否则返回 null

这是 var_dump 结果

13" ["nicename"]=> 字符串(9) "ridertest" } [5]=> 数组(6) { ["id"]=> 字符串(2) "52" ["post_content"]=> 字符串( 200)“能够维持其化学成分并决定其化学和化学物理性质和行为的物质的最小数量;可以由两个或多个组成" ["post_title"]=> string(52) "测试第一篇文章,蓝黄红绿浅蓝" ["post_type"]=> string(4) "post" ["post_date_gmt"] = > 字符串(19) "2017-03-25 11:14:46" ["nicename"]=> 字符串(9) "ridertest" } [6]=> 数组(6) { ["id"]=> 字符串(1) "1" ["post_content"]=> string(200) "可以选择主题,自定义工具栏,通过广告横幅赚钱并开始写作。编辑本文" ["post_title"]=> string(17) "第一篇文章" ["post_type"]=> string(4) "post" ["post_date_gmt"]=> string(19) "2011-07- 05 12:19:18" ["nicename"]=> string(9) "ridertest" } }

正如你在这里看到的,我拥有所有数据,为什么 json_encode 将它们设置为 null?


解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/548919/c5a9962a3d1831d34cb7/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

11 0
收藏该文
已收藏

评论内容:(最多支持255个字符)