My question is what is the best and most efficient way to save a large php array to a mysql table. I know there are a lot of methods out there to do this and I have tried a few of them but I still havent found a method I really feel comfortable using. The main method most people recommend is the serialize() and unserialize() php functions. For some reason this is not working for me and I seem to have tried every way to fix this but idk.
Here is my code:
// unserialize songs, add new song to end of array, and then re-serialize to add to db
$cereal = unserialize($dbsongs);
$pushed = array_push($cereal, $_GET['song']);
$songs = serialize($pushed);
//update playlists table
$stmt = $dbh->prepare("UPDATE playlists SET songs=:songs WHERE title=:title AND user=:user");
$stmt->bindParam(':user', $_SESSION['username'], PDO::PARAM_STR);
$stmt->bindParam(':title', $_GET['title'], PDO::PARAM_STR);
$stmt->bindParam(':songs', $songs, PDO::PARAM_STR);
$stmt->execute();
So first I unserialize $dbsongs which is the blank list of serialized data from a mysql table. Then i push $_GET['song'] to the array with array_push(). Then I serialize that and store it to db. For some reason this isn't working, but I would also like to know if there is a better way.
Should I try breaking up the php array and saving each item to a table and separating the items by a comma and them breaking that string when I retrieve it from the db?
Or should I just fix this method I am using? Or even add the base64_decode() and base64_encode()? These methods seems kinda old from some of the things I have read... http://www.evolt.org/node/60222
I have seen a method using .implode but I cannot figure out how to use it...Link 1 Link 2. This looks like the most modern approach I have seen. Is this what I should look into further?
Not sure what this method is but it mentions Cakephp which I suppose is a php library. Is this a good method?Link 1
I am going to be storing a lot of items in these lists(like over 1k items regularly), so I'm not even sure if if saving these items to one table field would be appropriate. Would simply making a table for these items be the best method since the list is going to be song large(making a new db entry for each new item added and making a "title" field to link them all together)? I have never experimented with something like this because I could never find enough information about how much data mysql could actually hold without problems arising.
I know there are a lot of questions here but any answers would be greatly appreciated! Thanks in advance!
-BAH