I have a web app which is basically one page with a single form broken down into tabs, each containing data from separate database tables. The form action points to a save.php script which takes the form data and saves it into the database.
我有一个web应用程序,它基本上是一个页面,一个表单被分解成标签,每个标签包含来自不同数据库表的数据。表单动作指向保存。php脚本,它接受表单数据并将其保存到数据库中。
The save.php script is structured so that it is composed of multiple SQL INSERT/UPDATE statements, one for each database table. It's done this way because some form tabs are hidden based on user preferences etc so a variable number of those statements will actually be run at any time.
保存。php脚本的结构是由多个SQL INSERT/UPDATE语句组成,每个数据库表一个SQL INSERT/UPDATE语句。它是这样做的,因为有些表单标签是基于用户偏好等而隐藏的,所以这些语句的数量是可变的。
Is there any way I can determine when all SQL queries have finished executing so that I can redirect the user to another page?
是否有办法确定所有SQL查询何时完成,以便将用户重定向到另一个页面?
As a quick example, the save.php script is composed of several blocks of code which basically look like this:
作为一个简单的例子,save。php脚本由几个代码块组成,基本上是这样的:
$updQuery = "UPDATE exampletable SET row=1 WHERE x=y";
try {
$updResult = odbc_exec($connect,$updQuery);
}
catch (RuntimeException $e) {
ExceptionHandlingStuff();
}
Normally for a redirect I'd just use a meta-refresh like so:
通常,对于重定向,我只需要使用元刷新如下:
<meta http-equiv="refresh" content="10; URL=homepage.php">
I can set it to a long delay like 10 seconds to be 'reasonably' sure all the SQL queries will have executed by the time the refresh kicks in but this seems like a horrible hack that offers no guarantee and causes unnecessary delay for the user, because the queries will almost always have completed long before the 10 second delay is over.
我可以将它设置为10秒这样的长时间的推迟是“合理的”确定执行的所有SQL查询将会刷新的时候,但这似乎是一个可怕的攻击,为用户提供任何保证,导致不必要的延误,因为查询几乎总是有10秒延迟结束之前完成。
What is the best way to detect when all SQL INSERT/UPDATE statements on a page have finished executing so that I can redirect the user immediately afterwards?
当页面上的所有SQL INSERT/UPDATE语句都已执行完毕,以便我可以立即重定向用户时,最好的检测方法是什么?
For reference I'm using PHP and ODBC to connect to a 4D SQL ANSI-92 database.
我使用PHP和ODBC连接到4D SQL ANSI-92数据库。
1 个解决方案
#1
2
That exec command is not run in parallel to other queries. This update is finished when you either catch an exception or fall to the next line of code after the catch block. So, given the limited information here, I would say redirect at the bottom of save.php like so:
exec命令不与其他查询并行运行。当您捕获异常或在catch块之后切换到下一行代码时,此更新就完成了。考虑到这里的有限信息,我在save的底部写上重定向。php一样:
$statusCode = ($statusCode ?: 200);
$statusCodeMessage = ($statusCodeMessage ?: '');
$forwardingUrl = ($forwardingUrl ?: 'http://www.google.com/');
header(sprintf("HTTP/1.1 %d %s", $statusCode, $statusCodeMessage));
header('Location: ' . $forwardingUrl);
#1
2
That exec command is not run in parallel to other queries. This update is finished when you either catch an exception or fall to the next line of code after the catch block. So, given the limited information here, I would say redirect at the bottom of save.php like so:
exec命令不与其他查询并行运行。当您捕获异常或在catch块之后切换到下一行代码时,此更新就完成了。考虑到这里的有限信息,我在save的底部写上重定向。php一样:
$statusCode = ($statusCode ?: 200);
$statusCodeMessage = ($statusCodeMessage ?: '');
$forwardingUrl = ($forwardingUrl ?: 'http://www.google.com/');
header(sprintf("HTTP/1.1 %d %s", $statusCode, $statusCodeMessage));
header('Location: ' . $forwardingUrl);