How to execute two different insert statements simultaneously in php
Source: Internet
Author: User
In php, how does one execute two different insert statements at the same time ;? PhpclassSqlTool {public $ link; public $ hostName = & quot; localhost & quot; public $ userName = & quot; root & quot ;; how to execute two different insert statements simultaneously in p php
Class SqlTool {
Public $ link;
Public $ hostName = "localhost ";
Public $ userName = "root ";
Public $ userPwd = "";
Public $ db_Name = "qlzx ";
Public function execute_dml ($ SQL ){
$ Res = $ this-> link-> query ($ SQL) or die ($ this-> link-> error );
If (! $ Res) return 0;
Else {
If ($ this-> link-> affected_rows> 0) return 1;
Else return 2;
}
}
}
$ SqlTool = new SqlTool ();
Can the statement be successfully executed in this way?
------ Solution --------------------
No, at least your SQL statements should be separated by semicolons.
I'm more curious about why you have such a strange requirement. separate execution not only facilitates troubleshooting, but also ensures security.
------ Solution --------------------
Transactions
------ Solution --------------------
Writing separately does not cost much.
Last_insert_id () is completely unnecessary and ID is auto-incrementing, so you do not need to specify it. Any database designer can consider any problems that may occur with auto-increment keys and solve them in the development stage.
------ Solution --------------------
No!
Only one SQL command can be executed at a time. This is a built-in measure of php to prevent SQL attacks. do not try to break through it.
The same is true if the database connection is not disconnected.
------ Solution --------------------
Use transactions.
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