这是我的查询;在我的数据库中,所有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”: “wwwwwwwwwwwwwwwww”, “post_type”: “后”, “post_date_gmt”:“2017年3月25日12点33分37" 秒, “nicename”: “ridertest”},{ “ID”: “66”, “POST_CONTENT”:NULL, “POST_TITLE”: “porova”, “post_type”: “后”, “post_date_gmt” : “2017年3月25日12点30分06秒”, “nicename”: “ridertest”},{ “ID”: “64”, “POST_CONTENT”: “ytytytyttytytytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttvvvvvvvv”, “POST_TITLE”: “ytytytytytyt”,“post_type “:” 后 “ ”post_date_gmt“: ”2017年3月25日12时28分五十秒“, ”nicename“: ”ridertest“},{ ”ID“: ”56“, ”POST_CONTENT“: ”aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa“,” post_title“:”Prova Prova Prova Prova Prova Prova Prova Prova Prova Prova“,”po st_type“:”post“,”post_date_gmt“:”2017-03-25 11:34:13“,”nicename“:”ridertest“},{”id“:”52“,”post_content“:null,”post_title “:”Prova primo articolo,blu 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“}]
如果我使用substring(char(200))一部分没有重音的char返回一个值,否则返回null
这是var_dump结果
array(7){[0] => array(6){[“id”] => string(2)“74”[“post_content”] => string(200)“Un trionfo di retorica,frutto di divisioni e diktat di Paesi(Polonia e Grecia,in primis)che hanno preteso modifiche al testo prima di garantire il proprio placet.Sull'Europaapiùvelocità,annun”[“post_title “] => string(60)“Nei Trattati quel riferimento soft a un'Europa a”intensità“[”post_type“] => string(4)”post“[”post_date_gmt“] => string(19)”2017-03- 25 12:54:35“[”nicename“] => string(9)”ridertest“} [1] => array(6){[”id“] => string(2)”72“[ “post_content”] => string(200)“Milano(/”[“post_title”] => string(17)“wwwwwwwwwwwwwww”[“post_type”] => string(4)“post”[“post_date_gmt” ] => string(19)“2017-03-25 12:33:37”[“nicename”] => string(9)“ridertest”} [2] => array(6){[“id “] => string(2)”66“[”post_content“] => string(200)”Milano(/“[”post_title“] => string(6)”porova“[”post_type“] = > string(4)“post”[“post_date_gmt”] => string(19)“2017-03-25 12:30:06”[“nicename”] => string(9)“ridertest”} [ 3] =>阵列(6){[ “ID”] =>串(2) “64”[ “POST_CONTENT”] =>串(141), “ytytytyttytytytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttvvvvvvvv”[ “POST_TITLE”] => ST ring(12)“ytytytytytyt”[“post_type”] => string(4)“post”[“post_date_gmt”] => string(19)“2017-03-25 12:28:50”[“nicename”] => string(9)“ridertest”} [4] => array(6){[“id”] => string(2)“56”[“post_content”] =>串(200) “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”[ “POST_TITLE”] => string(60)“Prova Prova Prova Prova Prova Prova Prova Prova Prova Prova”[“post_type”] => string(4)“post”[“post_date_gmt”] => string(19)“2017-03-25 11:34:13”[“nicename”] => string(9)“ridertest”} [5] => array(6){[“id”] => string(2)“52”[“post_content”] => string(200)“lapiùpiccolaquantitàdiuna sostanza in grado di conservarne la composizione chimica e di determinarne leproprietàeil comportamento chimico e chimico-fisico;puòesterrecostituita da dueopiùa”[“post_title”] => string(52)“Prova primo articolo,blu giallo rosso verde azzurro”[“post_type”] => string(4)“post”[“post_date_gmt”] => string(19)“2017-03-25 11:14:46”[“nicename”] => string(9)“ridertest”} [6] => array(6){[“id”] => string(1)“1”[“post_content”] => string(200)“Puoi scegliere il tema,personalizzare la toolbar,guadagnare con i banner pubblicitari e iniziare a scrivere.Modifica questo arti”[“post_title”] => string(17)“Il Primo Articolo”[“post_type”] => string(4)“post”[“post_date_gmt”] => string(19)“2011-07-05 12:19:18”[“nicename”] => string(9)“ridertest”}}
正如你在这里看到的,我有所有的数据,为什么json_encode将它们设置为null ??