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 );
...................