0

I have a 2-dimensional array that I need to insert into MySQL table. I know I can either use PDO prepared statement and loop through the array to pass the values into the prepared statement or I can generate a huge sql statement looping through the array and using implode function on the array. I've seen both methods described in this forum. My question is, which one is faster, why would you use one method versus the other one.

Note: The array I will be inserting has thousands of rows which, if I use method 2 would generate a huge SQL statement. Is there any limit as to how long the sql statement can be?

user2395238
  • 850
  • 1
  • 9
  • 20
  • Check max_allowed_packet variable in mysql to learn, what's the max length of the query. You can adjust it. http://stackoverflow.com/questions/16335011/what-is-maximum-query-size-for-mysql – user4035 Jan 10 '14 at 06:29
  • So there actually is a limit. I guess it's better to use PDO prepared statements. Will the performance be hurt? – user2395238 Jan 10 '14 at 08:35
  • This limit is valid for PDO too. The performance will be hurt a little: you'll spent resources on escaping. – user4035 Jan 10 '14 at 08:50

0 Answers0