运行此查询时返回 false [英] Returns false when running this query
本文介绍了运行此查询时返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这不起作用?当我将查询打印到屏幕并通过 phpMyAdmin 运行它时,它可以工作.我省略了连接到数据库(MySQL)的部分.
Any reasons why this not work? When I print the query to screen and runs it through phpMyAdmin it works. I left out the part where I connect to the database (MySQL).
$query = "START TRANSACTION; ";
$query .= "INSERT INTO table1(text) VALUES('$question_description'); ";
for ($i = 0; $i < count($processed_answers); $i++) {
$query .= "INSERT INTO table2(question_id, text, serial_number, is_correct) ".
"VALUES($question_id, '".$processed_answers[$i]."', '".$serial_numbers[$i]."', 0); ";
}
foreach($categories as $category) {
$query .= "INSERT INTO table3 VALUES($question_id, $category); ";
}
$query .= "COMMIT; ";
$result = $db->query($query);
推荐答案
看起来您正在尝试运行多个语句,可能是通过 mysql_query()
或 mysqli->query()
只支持单条语句.相反,您需要使用 mysqli->multi_query()
或 mysql_multi_query()
执行此操作.
Looks like you are attempting to run multiple statements, possibly through a mysql_query()
or mysqli->query()
which only support single statements. Instead you need to execute this with mysqli->multi_query()
or mysql_multi_query()
.
这篇关于运行此查询时返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文