Reply content:
225-228 pages of "High Performance MySQL" book. It's very detailed and I'll simply sort it out:
Benefits:
(1) Parse the query only once
(2) Perform some query optimization steps only once
(3) Sending parameters via the binary protocol is more efficient than sending them as ASCII text
For example, date, for Prepare, send date only with 3 Bytes, if there is no Prepare, date must be sent as a String, need to parse the database side, so that the need to send a Bytes.
(4) Only the parameters (not the entire query text) need to is sent for each execution
(5) MySQL stores the parameteres directly to buffers on the server
(6) Also helps with security, there are no need to escape or quote values.
Harm:
(1) Local to a connection, so another connection cannot re-use
(2) cannot use MySQL query cache (before version 5.1)
(3) Not all efficient, if you use it only once
(4) cannot use inside a stored function (stored procedure is possible)
(5) may leads to "leak" if your forget to deallocate it
Basically directly to the original text, part of the place slightly changed, and the appropriate place added. 1: Security, SQL injection of this kind of problem
2: Transfer volume optimization [parametric pass]
3: Avoid repeated parsing, MySQL is a non-holding connection function and mysqli is always connected function.
That is, MySQL each link will open a connected process and mysqli multiple runs mysqli will use the same connection process, thereby reducing the cost of the server