How to Implement MySQL multi-Table insertion

Source: Internet
Author: User

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:

 
 
  1. <? Php
  2. $ Conn = mysql_connect ("localhost", "charles", "charles ");
  3. Mysql_select_db ("test ");
  4. $ Query = "insert into contact (user_name, nom, prenom, mail, passcode) values ('sa ', 'se', 'sf', 'safd @ p.com ', '123 ')";
  5. $ Result = mysql_query ($ query) or die ("insert contact failed:". mysql_error ());
  6. $ Lastid = mysql_insert_id (); // obtain the id value of the previous insert.
  7. Echo "last insert id:". $ lastid. "<br> ";
  8. $ Query2 = "insert into contactdroit (contact_id, droit_id) values ('$ lastid', '11 ')";
  9. Echo $ query2. "<br> ";
  10. $ Result2 = mysql_query ($ query2) or die ("insert contactdroit failed:". mysql_error ());
  11. If (isset ($ result) & isset ($ result2 )){
  12. Echo "Good Insertion <br> ";
  13. Echo $ lastid;
  14. }
  15. ?>

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

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.