如何序列化查询数组结果并存储在数据库表中

时间:2012-06-08 09:29:32

标签: php sql serialization

如何序列化此结果并将其存储在数据库中;

Array
(
[0] => stdClass Object
    (
        [ingredientID] => 2
        [code] => Bf
        [description] => 1st Class Flour
        [volume] => 8268
        [price] => 750
        [amount_gram] => 0.02980
        [status] => Inactive
        [uom_id] => 1
        [flour] => Yes
    )

[1] => stdClass Object
    (
        [ingredientID] => 3
        [code] => Sf
        [description] => 3rd Class Flour
        [volume] => 18490
        [price] => 635
        [amount_gram] => 0.02540
        [status] => Inactive
        [uom_id] => 5
        [flour] => Yes
    )

[2] => stdClass Object
................

1 个答案:

答案 0 :(得分:3)

http://php.net/manual/en/function.serialize.php

$i = serialize($var2serialized);

$i将包含数组的序列化形式。

然后,您需要将$i作为数据库查询的一部分添加到商店。