Codeigniter PHP中将数组存储为JSON在数据库中无法正常工作
P粉012875927
P粉012875927 2024-04-02 00:08:37
0
1
479

我正在尝试使用 codeigniter 网站将数组作为 json 存储在数据库中,如下所示:

$this->db->insert('orders', 
                array('orderstatus' => $orderstatus,  
                      'productname' => json_encode($product1)
                    )
    );

数组的值如下:

Array
(
    [0] => Array
        (
            [id] => 8
            [productname] => Couple Combo Sherwani
            [pimage] => _RJ_0149-min.jpg,_RJ_0342-min.jpg,_RJ_0115-min.jpg
            [jrp] => 6000
            [deposit] => 6000
            [size] => XL
            [duration] => 3
            [quantity] => 1
        )

)

数据库看起来像:

但是在数据库中,该值存储如下:

"Array"

谁能告诉我这里出了什么问题吗,提前谢谢

P粉012875927
P粉012875927

全部回复(1)
P粉848442185

对我来说它有效:

$products = [
    (object)[
        "name" => "Test product",
        "attribute1" => "Value1"
    ]
];

$this->db->table("orders")->insert([
    "name" => "Order for client",
    "info" => "Client want this order today",
    "products" => json_encode($products)
]); //In products column i have [{"name":"Test product","attribute1":"Value1"}]
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板