Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-25-2012, 10:01 AM   PM User | #1
rochellecanale
New to the CF scene

 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
rochellecanale is an unknown quantity at this point
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?
rochellecanale is offline   Reply With Quote
Old 09-25-2012, 03:55 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
codeigniter, mysql, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:04 AM.


Advertisement
Log in to turn off these ads.