Jump to content

foreach to insert multiple rows...


Kristoff1875

Recommended Posts

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?

 

 

 

 

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.

 


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.

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.