PHP operations on the database. Insert multiple tables at a time

Source: Internet
Author: User
PHP operations on the database. Insert multiple tables at a time
Public function add ($ u_id, $ name, $ big_classes) {if (! Self: $ object) {return 102;} $ SQL = 'Insert classes (cl_big_classes, cl_name) value ('. $ big_classes. ',\''. $ name. '\') '; $ this-> SQL-> query ($ SQL); if ($ this-> SQL-> affected_rows <= 0) {return 220 ;} $ last_id = $ this-> SQL-> insert_id; if ($ last_id) {$ SQL = 'Insert u_cl_link (u_id, cl_id) value ('. $ u_id. ','. $ last_id. ')'; // This sentence is obviously not the result of the previous sentence, but the result of the last sentence. The final result is 0, indicating that everything is normal, but the database only inserts the first one. The second line has not been executed yet. find the solution if ($ this-> SQL-> affected_rows <= 0) {return 222;} return 0 ;}}


In theory, two queries are executed separately. The second sentence will not be executed. However, the insert operation in the second sentence was not successful. I copied the second $ SQL statement to the command line for execution, and the insert operation was successful. what mechanism should I understand here. Please advise me,


Reply to discussion (solution)

But I didn't see
$ SQL = 'Insert u_cl_link (u_id, cl_id) value ('. $ u_id.', '. $ last_id .')';
Where is the SQL statement executed?

But I didn't see
$ SQL = 'Insert u_cl_link (u_id, cl_id) value ('. $ u_id.', '. $ last_id .')';
Where is the SQL statement executed?
Close the post immediately, hide it, and shame again. I checked it for half a day. I didn't write it.
$ This-> SQL-> query ($ SQL );
...................

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.