使用函数序列化并将数据数组插入数据库?

时间:2011-07-25 07:10:10

标签: php codeigniter

如何在数据库中插入带有函数serialize的数据数组<input name='hello[]'>

请给我一个简单的例子?

2 个答案:

答案 0 :(得分:0)

简单:

$sSerialized = serialize($sData);
INSERT INTO table SET field = ".myqsl_real_escape_string($sSerialized);

我不建议将序列化数据存储到您的数据库中。

对于codeigniter特定设置,我认为您可以看到http://codeigniter.com/user_guide/database/queries.html

答案 1 :(得分:0)

它就像......

控制器:

function foo()
{
    if( ! empty($_POST))
    {
       $hello = serialize($_POST['hello']);
       // You can do your database abstraction here, but is better to have these in your model
       // Btw, by using CI AR, all values are escaped automatically producing safer queries.
       $this->db->insert('some_table', array('hello' => $hello)); 
    }
    else
    {
       // do something
    }
}