What are the advantages of using Mysqli prepare statements in PHP?
Source: Internet
Author: User
0 reply: page 225-228 of the book "High Performance MySQL. I will give a brief explanation of the details:
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, for DATE, after Prepare, only 3 Bytes are used to send the Date. If there is no Prepare, the DATE must be sent in the String format and needs to be parsed by the database. Therefore, 10 Bytes must be sent.
(4) Only the parameters (not the entire query text) need to be sent for each execution
(5) MySQL stores the parameteres directly into buffers on the server
(6) Also helps with security, there is no need to escape or quote values.
Disadvantages:
(1) Local to a connection, so another connection cannot re-use
(2) Cannot use MySQL query cache (earlier than MySQL 5.1)
(3) Not always more efficient, if you use it only once
(4) Cannot use inside a stored function (Stored procedure is acceptable)
(5) May lead to "leak" if you forget to deallocate it
Basically, I typed the original text directly, and made some slight changes in some places, and added some supplements as appropriate. 1: security issues such as SQL Injection
2: Transmission volume optimization [parameter transfer]
3: avoid repeated parsing. mysql is a non-persistent connection function while mysqli is a permanent connection function.
That is to say, mysql will open a connection process at each link, and mysqli will use the same connection process to run mysqli multiple times, thus reducing the server overhead.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.