What are the benefits of PHP using MYSQLI's prepare statement?

Source: Internet
Author: User

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
  • Related Article

    Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.