Php + mysqli preprocessing technology to add, modify and delete multiple data entries, mysqli multiple _ PHP Tutorial

Source: Internet
Author: User
The php + mysqli preprocessing technology allows you to add, modify, and delete multiple data entries. The php + mysqli preprocessing technology allows you to add, modify, and delete multiple data entries, mysqli multiple cases this article describes how to add, modify, and delete multiple data records using the php + mysqli preprocessing technology to add, modify, and delete multiple data records, multiple mysqli entries

This article describes how to add, modify, and delete multiple data records using the php + mysqli preprocessing technology. Share it with you for your reference. The specific analysis is as follows:

First of all, why do we need preprocessing (pre-compilation) technology? For example, if you want to add 100 users to the database, the conventional approach is to send 100 execution requests to the database. in this case, according to the working principle of the mysql database, it needs to compile each execution statement (there are 100 times ). Therefore, the efficiency here is very low.

The function of preprocessing (pre-compilation) technology is to reduce the number and time of compilation to improve the effect. The following is a case study to illustrate how the preprocessing (pre-compilation) technology is implemented (well, let's clarify that when the php program sends an SQL statement for the first time, the mysql database is compiled, for the next 99 times, php only needs to send the data and does not need to compile it ).

<? Php // 1. create a database connection object $ mysqli = new MySQLi ("localhost", "root", "123456", "liuyan"); if ($ mysqli-> connect_error) {die ($ mysqli-> connect_error);} $ mysqli-> query ("set names 'gbk '"); // 2. create a pre-compiled object $ SQL = "insert into account (id, balance) values (?,?) "; // Used here? To replace the data value $ stmt = $ mysqli-> prepare ($ SQL); // return a statement object, for methods in the object, see MySQLi_STMT // 3. bind the parameter (data to be inserted) and run $ id = null; // here, my database is set to primary key auto_increment $ balance = 100.5; $ stmt-> bind_param ("id", $ id, $ balance); // bind the parameter, the return value is a Boolean value. "If" indicates the data type of the inserted data in order. // $ id is int, expressed in I, $ balance is float, and d is used, for details, see the manual $ res = $ stmt-> execute (); // execute the statement. the returned value is Boolean. // 4. determine whether the execution is successful. if (! $ Res) {echo "data insertion failed, balance value :". $ balance;} else {echo "successful";}/****** insert the second data entry * // 3. bind the parameter (the data to be inserted ), run $ id = null; // here, my database is set to primary key auto_increment $ balance = 400.3; $ stmt-> bind_param ("id", $ id, $ balance ); // bind the parameter. The return value is a Boolean value. "If" indicates the data type of the inserted data in sequence. // $ id is int, expressed by I, $ balance is float, and d. $ Res = $ stmt-> execute (); // execute the statement. the returned value is Boolean. // 4. determine whether the execution is successful. if (! $ Res) {echo "data insertion failed. the balance value is. $ balance ;}else {echo" success ";}?>

I hope this article will help you with php programming.

Examples in this article describes how to add, modify, and delete multiple data records using the php + mysqli preprocessing technology...

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.