A
A
alexey_khorin2021-06-21 07:45:51
MySQL
alexey_khorin, 2021-06-21 07:45:51

How can I add data to multiple tables with a single insert into?

A piece of code that adds a record to one table, but how to add it to two at once?

// Insert new record into the contacts table
    $stmt = $pdo->prepare('INSERT INTO `Client`(`id`, `surname`, `name`, `patron`, `serie`, `number`, `propiska`,`telephone`)  VALUES (?,?,?,?,?,?,?,?)');/*ошибка ,удалить `банк`*/
    $stmt->execute([$id, $surname, $name, $patron, $serie, $number, $propiska,$telephone,/*$ls,$balance,$date*/]);/*error*/

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin B., 2021-06-21
@alexey_khorin

$stmt = $pdo->prepare('INSERT INTO `Client`(`id`, `surname`, `name`, `patron`, `serie`, `number`, `propiska`,`telephone`)  VALUES (?,?,?,?,?,?,?,?)');/*ошибка ,удалить `банк`*/
    $stmt->execute([$id, $surname, $name, $patron, $serie, $number, $propiska,$telephone,/*$ls,$balance,$date*/]);/*error*/
    $stmt = $pdo->prepare('INSERT INTO `Client2`(`id`, `surname`, `name`, `patron`, `serie`, `number`, `propiska`,`telephone`)  VALUES (?,?,?,?,?,?,?,?)');/*ошибка ,удалить `банк`*/
    $stmt->execute([$id, $surname, $name, $patron, $serie, $number, $propiska,$telephone,/*$ls,$balance,$date*/]);/*error*/

A
Akina, 2021-06-21
@Akina

MySQL does not support multi-table INSERT.
Options:

  1. Stored procedure
  2. Trigger (but you need to solve the problem with passing parameters for other tables)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question