-
Hey there, I'm just wanting to understand what is the best practice.
I started to wonder because I noticed that Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
1 - yes, main reason to reuse connection is to reduce query/execute latency, especially in case of non-local mysql server. Each connection is more than one packet round trip and adds to a total query execution 2 - it depends,
If you have parameters ( |
Beta Was this translation helpful? Give feedback.
1 - yes, main reason to reuse connection is to reduce query/execute latency, especially in case of non-local mysql server. Each connection is more than one packet round trip and adds to a total query execution
2 - it depends,
.execute()
under the hood consist of 2 steps: prepare ( only for the first time .execute is used with this connection ) and then statement.execute. For short query that is already in the mysql server query cache performance might be identical ( or sometimes even better for .query() ). The main reason to use .execute is to avoid client side parameters serialization into sql string and potential security bugs if this serialization is not safe ( .execute does not need i…