Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy 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().
    Code:
    Array
    (
        [2] => Array
            (
                [id] => 2
                [product_name] => NOKIA 5110
                [product_desc] => Cellphone
                [product_price] => 500.00
                [product_qty] => 1
                [product_amount] => 500
                [product_code] => NOKI2012-84353
            )
    
        [3] => 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
            )
    
    )
    here is my actual array extract by unserialized function:
    Code:
    $products = unserialize($this->session->userdata('product_list'));
    How can i pas it to the database?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •