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

Source: Internet
Author: User
PHP operations on the database. Insert this post to multiple tables at a time and then edit public & nbsp; function & nbsp; add ($ u_id, & nbsp; $ name, & nbsp; $ big_classes) {& nbsp; if (! Self: $ object) & nbsp; & PHP operations on the database. Insert multiple tables at a time

This post was last edited by xuzuning at 19:00:56 on

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 article has not been executed yet. find a 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,

Database php insert SQL query


------ 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?

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.