The implementation of MySQL multi-Table insertion is not complex. The following describes the implementation process of MySQL multi-Table insertion in detail. If you are interested in MySQL multi-Table insertion, take a look.
MySQL multi-table insert:
- <? Php
- $ Conn = mysql_connect ("localhost", "charles", "charles ");
- Mysql_select_db ("test ");
- $ Query = "insert into contact (user_name, nom, prenom, mail, passcode) values ('sa ', 'se', 'sf', 'safd @ p.com ', '123 ')";
- $ Result = mysql_query ($ query) or die ("insert contact failed:". mysql_error ());
- $ Lastid = mysql_insert_id (); // obtain the id value of the previous insert.
- Echo "last insert id:". $ lastid. "<br> ";
- $ Query2 = "insert into contactdroit (contact_id, droit_id) values ('$ lastid', '11 ')";
- Echo $ query2. "<br> ";
- $ Result2 = mysql_query ($ query2) or die ("insert contactdroit failed:". mysql_error ());
- If (isset ($ result) & isset ($ result2 )){
- Echo "Good Insertion <br> ";
- Echo $ lastid;
- }
- ?>
Note that:
The mysql_insert_id () function returns the AUTO_INCREMENT ID generated from the previous INSERT operation.
The function mysql_insert_id () is used to obtain the ID generated by the previous INSERT operation.
This function returns 0 if the previous operation does not generate an AUTO_INCREMENT ID, or FALSE on MySQL connection failure.
If the previous operation does not generate an automatically added ID [AUTO_INCREMENT ID], the function returns 0. If the MySQL connection fails, False is returned.
Mysql temporary table usage
MySQL Stored Procedure for table splitting
In-depth discussion on MySQL Lock Mechanism
Detailed description of MySQL Data Table types
Add and delete fields in MySQL