У меня есть следующие таблицы:
thread: id, title, content, created
thread_tags: tag_id, thread_id
tag: id, name
author_threads: thread_id, author_id
Это то, что я обычно делаю, чтобы вставить значения во все эти поля (некоторые шаги были пропущены для простоты):
$sql_thread = "INSERT INTO thread (title, content)
VALUES ('some title', 'some content')";
# this is normally a loop, as there are more than one tags:
$sql_tags = "INSERT INTO tag (name)
VALUES ('onetag')";
# normally I would check the return value
mysqli_query($link, $sql_thread);
# get the thread id:
$thread_id = mysqli_insert_id($link);
mysqli_query($link, $sql_tags);
# get the tag id:
$tag_id = mysqli_insert_id($link);
# insert into thread_tags:
mysqli_query($link, "INSERT INTO thread_tags (thread_id, tag_id) VALUES ($thread_id, $tag_id)");
# insert into author_threads, I already know author_id:
mysqli_query($link, "INSERT INTO author_threads (author_id, thread_id) VALUES ($author_id, $thread_id)")
Я хочу убедиться, что все это происходит или ничего не происходит (т.е. процесс создания потока). Как я могу кодировать это, чтобы использовать транзакции? Или любой другой способ убедиться, что все это происходит?