Jacques1 Posted April 10, 2014 Share Posted April 10, 2014 You stated that every call of execute() creates a new prepared statement. I'd like to see evidence of this, because this is indeed an exceptional claim. My code above demonstrates that calling prepare() once and execute() 10 times leads to one prepared statement. This is exactly what I expected, but you obviously doubt this result. So where's your code which shows that actually 10 statements get created? Quote Link to comment https://forums.phpfreaks.com/topic/287635-foreach-to-insert-multiple-rows/page/2/#findComment-1475623 Share on other sites More sharing options...
jazzman1 Posted April 10, 2014 Share Posted April 10, 2014 You stated that every call of execute() creates a new prepared statement. Yes, I still stay behind that statement, but need to check how mysql treats execute statement in a loop. But what I've seen this morning than, most of the new versions of databases to improve the performance just prepared the query only once when execute statement occurred in a loop. Quote Link to comment https://forums.phpfreaks.com/topic/287635-foreach-to-insert-multiple-rows/page/2/#findComment-1475650 Share on other sites More sharing options...
Barand Posted April 10, 2014 Share Posted April 10, 2014 Repeated execution A prepared statement can be executed repeatedly. Upon every execution the current value of the bound variable is evaluated and sent to the server. The statement is not parsed again. The statement template is not transferred to the server again. Quote Link to comment https://forums.phpfreaks.com/topic/287635-foreach-to-insert-multiple-rows/page/2/#findComment-1475655 Share on other sites More sharing options...
jazzman1 Posted April 10, 2014 Share Posted April 10, 2014 Well, thanks for the quote Barry. I found the same in the mysql documentation, and I'd suggest @OP to read up on it. So, obviously, there is nothing wrong in Jacques's script to call execute statement in a loop as I thought and stay corrected on it. I become confused by the fact that all versions of Firebird DB ( before 2.5, not sure for older version of mysql ), every execute statement occurred in a loop was prepared, executed and released upon every iteration, however, you are here to learn something new everyday Quote Link to comment https://forums.phpfreaks.com/topic/287635-foreach-to-insert-multiple-rows/page/2/#findComment-1475672 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.