Welcome Guest, Not a member yet? Register   Sign In
[HELP NEEDED] array serialization and inserting into database
#1

[eluser]M52 Studios[/eluser]
Hey guys,

I need to serialize an array and insert it into the database. Two things are coming up as odd.

First of all, when I try to serialize an array and print it to screen it looks as it should.

Code:
a:9:{s:10:"legal_name";s:10:"legal name";s:12:"display_name";s:11:"public name";s:12:"live_support";s:2:"No";s:17:"reservation_phone";s:9:"123456789";s:7:"website";s:11:"www.www.com";s:16:"insured_vehicles";s:1:"6";s:10:"start_year";s:4:"1986";s:11:"association";s:2:"No";s:17:"short_description";s:25:"short company description";}

BUT

when I do a database insertion using similar code...

Code:
$foo = array();

$foo[] = 1;
$foo[] = 2;

$str = serialize($foo);

$data = array('part_1' => $str);

$this->db->insert('temp_form_data', $data);

I get two entries... one being identical to the one above under 'id' of 1, and another one that has no values, under 'id' of 2. So, for some odd reason, I'm getting two insertions.

Code:
a:9{s:10:"legal_name";N;s:12:"display_name";N;s:12:"live_support";N;s:17:"reservation_phone";N;s:7:"website";N;s:16:"insured_vehicles";N;s:10:"start_year";N;s:11:"association";N;s:17:"short_description";N;}

Has anyone else ran across this issue? If so, how did you fix it?

Another problem is when I try to update the other columns of the same table with similar serialized arrays, I am getting arrays that have no value, as my last example, but when I print them to screen, all the values are there. This has been breaking my head for most of the day. Anyone have any suggestions?

Thank you in advance.


Messages In This Thread
[HELP NEEDED] array serialization and inserting into database - by El Forum - 12-20-2010, 08:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB