Insert into 2 tables from 1 form. Mysql Transaction?

后端 未结 3 1846
南方客
南方客 2021-01-19 17:07

The user will create an article and submit an image with it.

+The article will go to the articles table.

+The image will go to images table (so that it can

3条回答
  •  庸人自扰
    2021-01-19 17:49

    $sql ='START TRANSACTION;
           INSERT INTO articles (article_id,article_title, article_text, article_date) VALUES (NULL,?, ?, NOW());
           INSERT INTO images (article_id, image_caption) VALUES(LAST_INSERT_ID(),?);
           COMMIT;';
    

提交回复
热议问题