php - Json数组数据在php中插入空值

标签 php mysql json

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_recieveddate_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/

相关文章:

php - 配置文件图像存储数据库或服务器系统

PHP PDO 异常 : SQLSTATE[HY093]

选择项目的 php/mysql 最佳实践

java - 如何从数据库(MySQL)中分块获取记录

android - 使用 retrofit/gson 解析迭代 json 对象

javascript - 如何在 Body 标签内使用 JSON 返回的数据

PHP + MySQL - 排序查询

PHP/MySQL - 需要帮助获取用户适用的事件列表

mysql - SQL请求,同一张表上的内部连接?

json - asp.net mvc 4 与 JavaScript 模板