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; I PHP operate 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 first and foremost, 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?