what is the best way to store a big array into a mySQL DB?
First solution
INSERT INTO `friendList` ( `userId` , `friendId` , `friendName` ) VALUES
( '1', '3242343', 'bernd' ),
( '1', '3242342', 'jusu' );
or with foreach
second solution
foreach (xxxx) {
mysql_query("insert xxxx");
}
The first solution is better (cleaner and not so burdensome for the server, right?), but how do a create this insert command?
The fastest would be to use the multiple insert syntax (as you’ve described), but that’s not what I would recommend to most people unless performance is truly vital. You also need to take care not to exceed the maximum query size (which can change between servers).
However, you could do this with prepared statements (PDO example) and still get reasonable performance: