Php 在提交事务之前显示日志文件。仅在用户确认后提交
当我更新数据中的记录时,我希望在提交事务之前向用户显示更新日志,并提供继续或回滚的选项 将更新提交到数据库的代码遵循以下格式:-Php 在提交事务之前显示日志文件。仅在用户确认后提交,php,jquery,logging,transactions,commit,Php,Jquery,Logging,Transactions,Commit,当我更新数据中的记录时,我希望在提交事务之前向用户显示更新日志,并提供继续或回滚的选项 将更新提交到数据库的代码遵循以下格式:- <?php include 'submitLogger.php'; // Begin logging ini_set( "error_log", $logFile ); ini_set( "log_errors", "On" ); ini_set( "display_errors", "Off" ); error_log( "Log file '" . $lo
<?php
include 'submitLogger.php';
// Begin logging
ini_set( "error_log", $logFile );
ini_set( "log_errors", "On" );
ini_set( "display_errors", "Off" );
error_log( "Log file '" . $logFile . "' created" );
// Open the database
.
.
error_log( "Connect OK" );
.
.
error_log( "Transaction started (autocommit OFF)\n" );
.
.
error_log( "Processing " . count( $deletes ) . " item(s) marked for deletion..." );
.
.
// commit changes
error_log( "Committing changes..." );
if ( mysqli_commit( $link ) === false ) {
mysqli_rollback( $link );
error_log( "Commit failed. Transaction rolled back." );
$response['error'] = "Could not commit changes. Transaction rolled back.";
} else {
error_log( "Commit successful!" );
$response['success'] = "Success!";
}
// close DB connection
.
.
// Return result
.
.
只要我知道你做不到。
至少不是用php。
Php是一个服务器端,脚本代码运行。
它从第一行到最后一行,停下来
但是,您可以运行一个select命令,告诉示例中将删除多少条记录,将这些数据提供给ajax,然后在确认后执行真正的删除操作(并提交更改)
但是,您可以(如果您的web应用程序被很多人使用)遇到这样的情况:您的ajax find 25元素将被删除,而真正的delete查询将删除26个或更多。为此,请重新考虑一下您的逻辑,并在删除查询后生成一个日志。更正Marco,似乎没有简单的解决方案。更新不会太多,因为只有管理员会使用此功能,但您的观点仍然有效,实际更新可能会与日志不同。请注意,您不能停止(在php中)事务,如果未提交,它将以回滚结束,事务状态与其他语言不同(这会有其他问题)。我想我必须在php代码中创建一些html,其中包含一个javascript提示符,该提示符将显示日志,并询问用户是否要继续。可能在“错误日志(“提交更改…”)之后声明。我只是不知道如何从用户那里得到响应。有什么想法吗?Marco?您可以创建两个Ajax函数。第一个函数要求选择“已选择的”元素,也是一个proto delete,它将告诉管理员将删除多少行。在此页面中,一个按钮将允许真正的删除。否则,您只能按id删除,您可以创建一个元素id为的数组,并使用ajax传递该数组以执行删除(从表中删除,其中id=$myvar)对于每个数组元素,它将更加安全。管理员/版主请关闭或删除此问题,因为似乎没有合理的解决方案
<script type="text/javascript">
$(document).ready( function() {
// send AJAX request to perform the updates and begin logging
$.post(
'../lib/updateMenu.php',
sendData,
function( response ) {
// was it successful?
if ( typeof response.success === 'undefined' ) {
// no - show alert
if ( response.error ) {
alert( response.error );
}
console.error( "Amend not successful" );
console.error( response );
return;
}
// delete the AmendmenuAmendselected program window to force a reload on next click
$( "#programWindowAmendmenuAmendselected" ).remove();
},
"json"
).error(function(jqXHR, textStatus, errorThrown) {
alert( 'Unexpected error: ' + textStatus + ' ' + errorThrown );
console.error( 'Unexpected error during amend: ' + textStatus + ' ' + errorThrown );
console.error(jqXHR);
}).complete(function() {
// once a reply is received, stop the logging
ajaxLogtail.stopTail();
});
// begin querying log file
var ajaxLogtail = new AjaxLogtail( '../lib/ajaxLogtail.php?logfile=' + logFile, "programWindowAmendmenuSubmit" );
ajaxLogtail.startTail();
});
</script>