Json 数组数据在 php.ini 中插入空值你好,我有这个 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
)
这就是我的插入语句的样子
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
或空数据。
我如何将消息内容/正文插入数据库。
任何帮助将不胜感激
最佳答案
你的值(value)观是错误的......
$statement->execute(array(
':date_received' => $value[0]['date_received'],
':date_indexed' => $value[0]['date_indexed'],
':message_content' => $value[0]['body'][0]['content']
));
你的转储似乎缺少 3 个右括号。
关于php - Json数组数据在php中插入空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31149022/