Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
09-25-2012, 10:01 AM #1
- Join Date
- Sep 2012
- Thanked 0 Times in 0 Posts
Store MultiDimensional Array To Mysqk
hello guys i need a little help hope you can help me. My problem is i want to store my array information in the database.
Here's my array sample array layout that generated by var_dump().
Array (  => Array ( [id] => 2 [product_name] => NOKIA 5110 [product_desc] => Cellphone [product_price] => 500.00 [product_qty] => 1 [product_amount] => 500 [product_code] => NOKI2012-84353 )  => Array ( [id] => 3 [product_name] => HP IPAQ RW6828 [product_desc] => Cellphone [product_price] => 1500.00 [product_qty] => 1 [product_amount] => 1500 [product_code] => HP I2012-08386 ) )
$products = unserialize($this->session->userdata('product_list'));
09-25-2012, 03:55 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,660 Times in 2,629 Posts
By using serialize instead.
Is this persisting data? Given its name, I'd suspect this to be temporary data (such as a session)? If the data is persisting, then I'd not suggest that serialize/unserialize should ever be used; a normalization of the database would be the better solution. You cannot (easily) search for a "list" in a single property, but you can easily search a flattening table.
With (often unknown) temporary data assuming a session, you should actually look at using the session_set_save_handler with either functions or with the SessionHandlerInterface (5.4+). Simply write the functions for handling it at a database instead of at a file level and specify the class or individual functions.