我正在尝试使用PHP中的代码在mySQL中删除并创建一个视图:
$hours_sum_build = "DROP VIEW hours_sum;";
$hours_sum_build .= "CREATE VIEW hours_sum as
SELECT emp_id, first_name, last_name, pp_end, date, sum(hours) as
hours, time_source, run_date, run_time
FROM merged_time_report GROUP BY emp_id";
mysqli_multi_query($conn, $hours_sum_build);
echo "Debug: $hours_sum_build";
$result = mysqli_multi_query($conn, $hours_sum_build);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($conn));
}
else {
echo 'done.';
}
我显然希望DROP视图然后立即再创建它。但是,当我运行上面的代码时,我收到此错误消息:
Debug: DROP VIEW hours_sum;CREATE VIEW hours_sum as
SELECT emp_id, first_name, last_name, pp_end, date, sum(hours) as
hours, time_source, run_date, run_time
FROM merged_time_report GROUP BY emp_id
error:
Commands out of sync; you can't run this command now
null results for hours_sum_count
null results for first_pass_count
null results for pass_fail_count
Error:
Commands out of sync; you can't run this command now
Error:
Commands out of sync; you can't run this command now
Error:
Commands out of sync; you can't run this command now
null
创建视图时(我可以通过phpMyAdmin完成),它会返回上面标识的三个变量(hours_sum_count等)中的结果,因此在我的场景中这些是空的,因为视图不是使用mysqli_multi_query在PHP中创建。
感谢您的帮助!