我正在嘗試使用 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粉8484421852024-04-02 17:32:20
對我來說它有效:
$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"}]