Insert data to multiple tables in php

Source: Internet
Author: User
Insert data tables to multiple tables in php: order_table & nbsp; field: order_id, (table :) rem_table.rem_id (primary key), order_number table: deal_table & nbsp; & nbsp; & n insert data into multiple tables in php
Table: order_table
Field: order_id, (table :) rem_table.rem_id (primary key), order_number
Table: deal_table
Fields: deal_id, order_id, deal_date, deal_information, and deal_man

Insert data into these two tables: order_number, deal_date, deal_information, and deal_man.

What should I do! When inserting data, the field rem_table.rem_id cannot be blank, because it will be used for data query in the future. (query of rem_table and order_table)

------ Solution --------------------
Use If to judge and then insert.

If ()
{
Insert ();
Mysql-> query ();
Inser ();
Mysql-> query ();
}
Else
{
}
------ Solution --------------------
The order table is the "father" of the deal table (according to the design of your table)
So there is (insert) order first and then (insert) deal
Two options
1. Use Database auto-increment ① insert order ② query order_id ③ insert deal
2. ID generated using PHP ① insert order (write the generated ID directly) ② insert deal

If method 2 is used, note that the ID must be complex, just as the image name is generated and cannot be repeated.

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.