Storing array as JSON in Codeigniter PHP not working properly in database
P粉012875927
P粉012875927 2024-04-02 00:08:37
0
1
330

I'm trying to use the codeigniter website to store an array as json in a database like this:

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

The values ​​of the array are as follows:

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
        )

)

The database looks like:

But in the database, the value is stored as follows:

"Array"

Can anyone tell me what's wrong here, thank you in advance

P粉012875927
P粉012875927

reply all(1)
P粉848442185

For me it works:

$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"}]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!