A
A
Albert2021-06-14 12:58:10
PHP
Albert, 2021-06-14 12:58:10

How to write data to 2 related tables at once?

PDO MYSQL

Guys how can I send data to several related tables at once?
There is a form with the usual data Field1 Field 2 and photos.

Fields (1 and 2) must be sent to 1 table, and photos to the 2nd table.

I know that you need to first send the Fields to table 1 and get an id, then insert this id into table 2 with a photo so that they are connected.

But how can this be implemented? Does anyone have any examples

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gian_tiaga, 2021-06-14
@timurusubyan

What DB what driver?
If via PDO methods exec for INSERT after lastInsertId to get ID after exec INSERT for second

I
index0h, 2021-06-14
@index0h

1. open a transaction
2. write to one table
3. write to another table
4. commit the transaction

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question