Welcome Guest, Not a member yet? Register   Sign In
Store multi dimensional Array in database: function.unserialize Error at offset
#1

[eluser]Trankh1[/eluser]
Hello,

I want to store in session a multiarray with 1500 records.

This is an example which reproduces the error:
Code:
for ($i = 1; $i < 1500;$i++) {
  $array = array("name" => "igor", "website" => "facebook.com", "age" => "32");
  array_push($array_test, $array);

     }
    
     $this->session->set_userdata('myarray',  $array_test);
    print_r( $this->session->userdata('myarray'));

I use the traditionnal Session->set_userdata function.

The problem is :
Code:
Severity: Notice  --&gt; unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 65531 of 65535 bytes system/libraries/Session.php 726
I have tried json_encode the array before storing but it is the same error.
I have tried with a multiarray of 500 and no error.

Have you guys solutions to this pattern (storing big array in session)?

Data stored into this array are from social network api call and are just used for the session .


Thanks!


I'm using CodeIgniter (and mysql) with session handling in database.
My user_data column in db is text type and utf8_general_ci encoded.

This is my session config part file:
Code:
$config['sess_cookie_name']             = 'ci_session';
$config['sess_expiration']              = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = TRUE;  
$config['sess_use_database'] = TRUE;
$config['sess_table_name']              = 'ci_sessions';
$config['sess_match_ip']                = FALSE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update']  = 300;
#2

[eluser]Trankh1[/eluser]
I have changed my db column type from text to longtext and it works.

But as for you, is this always the best way to store data?
#3

[eluser]InsiteFX[/eluser]
I would be asking myself why do I need to store 1500 records into my session?
#4

[eluser]CroNiX[/eluser]
query caching is cheap Smile
#5

[eluser]Trankh1[/eluser]
Stored Array is a list of contacts picked up from social networks api like facebook or linkedin.
I want to avoid to store these data in database when I don't need them for confidentiality reasons.

So, I think, storing data serialized (as session works for CodeIgniter) in a single column could be a good way but maybe i'm totally wrong.

During user session, I need sometimes to research on the merged array by name and this is my single need about querying these data.
So far, I store this array in ci_sessions_tables and when I need to research by name, I call session variable and I loop once in PHP (with a preg_match). It's fast enough.

But what do you think of that?

I'm totally opened to your suggestions.
#6

[eluser]InsiteFX[/eluser]
I think it would be faster using a database table with an index and query caching like CroNiX mentioned above!




Theme © iAndrew 2016 - Forum software by © MyBB