Json Array数据在php中插入Null值。您好,我有这个想要插入数据库的Json数组数据。除了消息正文/内容插入空值
外,一切正常Array (
[0] => Array (
[date] => 1435697125
[folders] => Array (
[0] => \Important
[1] => INBOX
[2] => \Inbox
[3] => [Gmail]/Important
)
[addresses] => Array (
[from] => Array (
[email] => chine@gmail.com
[name] => chinelo Goodman
)
[to] => Array (
[0] => Array (
[email] => mic@gmail.com
[name] => michael noway
)
)
)
[sources] => Array (
[0] => Array (
[label] => mic::gmail
[resource_url] => http://myserver.com
)
)
[subject] => Re: Testing of Data
[references] => Array (
[0] =>
[1] =>
[2] =>
)
[in_reply_to] =>
[id1] => 55930
[id2] =>
[id3] => 14e46
[thread_id] => 14e45
[person_info] => Array (
[chine@gmail.com] => Array (
[thumbnail] => http://localhost/contact.png
)
[mic@gmail.com] => Array (
[thumbnail] => https://localhost/mic.png
)
)
[date_received] => 1435697125
[date_indexed] => 1435697307
[body] => Array (
[0] => Array (
[type] => text/plain
[charset] => utf-8
[content] =>
Thank You. I hope to hear from you sooneer On
Tue, Jun 30, 2015 at 1:25 PM, mic wrote: >
ssfddfd dgffgff fhfghhf ffhhfhhhg ghghg > > On
Tue, Jun 30, 2015 at 12:41 PM, mic > wrote: > >>
i see it >> >> On Tue, Jun 30, 2015 at 12:38 PM,
chinelo > > wrote: >> >>> my message is here >>>
Testing going on >>> >> >> >
[body_section] => 1
)
这是我的insert语句的样子
foreach ($result as $value) {
}
$statement= $db->prepare('
INSERT INTO
json_table(
date_received,
date_indexed,
message_content
)
values (
:date_received,
:date_indexed,:message_content)
');
$statement->execute(
array(
':date_received' => $value['date_received'],
':date_indexed' => $value['date_indexed'],
':message_content' => $value['addresses']['body'][0]['type']['charset']['content']
)
);
在date_recieved
不断插入date_indexed
或空数据时插入message_content
和NULL
。
我如何将消息内容/正文插入数据库。
任何帮助将不胜感激
答案 0 :(得分:0)
你的价值观错了......
$statement->execute(array(
':date_received' => $value[0]['date_received'],
':date_indexed' => $value[0]['date_indexed'],
':message_content' => $value[0]['body'][0]['content']
));
你的转储似乎缺少3个右括号。
答案 1 :(得分:0)
不确定你为什么
':message_content'=> $值[ '地址'] [ '体'] [0] [ '型'] [ '字符集'] [ '内容']
类型,字符集和内容是同一级别的不同元素,您只需要这个
':message_content'=> $值[ '地址'] [ '体'] [0] [ '内容']