我正在尝试做这样的事情:
SET @grade_id = (SELECT grade_id FROM grades_table WHERE grades = '1' AND sections = 'A');
SET @subject_id = (SELECT subject_id FROM subjects_table WHERE grade_id = @grade_id AND subject_name = 'Maths' AND teacher_id = '1');
INSERT INTO topics_table ( subject_id, grade_id, topic_name) VALUES (@subject_id, @grade_id,'Another Topic');
这在 phpmyadmin 中有效,但在 Visual Studio Code 中与 PHP 一起使用时无效。我在 VSC 中这样做:
$topic = "SET @grade_id = (SELECT grade_id FROM grades_table WHERE grades = '1' AND sections = 'A');
SET @subject_id = (SELECT subject_id FROM subjects_table WHERE grade_id = @grade_id AND subject_name = 'Maths' AND teacher_id = '1');
INSERT INTO topics_table ( subject_id, grade_id, topic_name) VALUES (@subject_id, @grade_id,'Another Topic')";
mysqli_multi_query(
$connection,
$topic
);
mysqli_close($connection);