Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] PHP Storing multi Dimensional array data in MySQL


[SOLVED] PHP Storing multi Dimensional array data in MySQL

Reply
  #1 (permalink)  
Old 04-10-08, 09:16 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
[SOLVED] PHP Storing multi Dimensional array data in MySQL

Now Ive always been told the easiest way to store data in mysql thats in a multi dimensional array is by serializing the array and then inserting into MySQL

Now im using the php function serialize() no problem what so ever and inserting the serialized data into a LONGTEXT field in MySQL. When the data comes out the other end I just unserialize the data. but sometimes only half of the data is inserted. It seems to be when we insert a very large multi dimensional array.

The data I store is for a user and what websites that user has accessed and what bandwidth he used on each webpage. Now a user might go on 100 different urls a day and then on top of it HR might do a custom report on the user for a months usage giving 1000+ different websites accessed.

Now I thought that LONGTEXT could store over 1GB of data in its field? Surely my serialized array doesnt come to sizes of that? So what could be causing my big arrays to only insert half the data?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-11-08, 03:45 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
I found 2 possible solutions on php.net:

www.php.net/serialize#79339
Not sure what he means with "behave a bit crazy", but it might the same problem you're facing.

www.php.net/serialize#61675
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-11-08, 05:12 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
thx nico maybe i should just run the serialized data through mysql_real_escape_string(); before putting it into the database??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-11-08, 05:17 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You should do that always anyway. (Unless it's just a very simple string or an integer)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Comparing MySQL data with PHP mike_jandreau PHP 10 03-08-09 06:12 PM
PHP not recognizing admin in MySQL gizelle Database 3 04-15-07 09:39 PM
xml to mysql using php - urgent mianriz PHP 1 12-21-06 04:51 PM
Inserting data to mysql table using php Tjobbe PHP 4 09-28-06 07:37 AM
Pulling data from MySQl Database w/ PHP? dayzeday PHP 6 10-07-03 08:01 AM


All times are GMT -5. The time now is 10:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.