【发布时间】:2015-01-09 12:35:42
【问题描述】:
当我更新数据中的记录时,我想在事务提交之前向用户显示更新日志,并提供继续或回滚的选项。
将更新提交到数据库的代码遵循以下格式:-
<?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
.
.
这是加载上面更新代码然后显示日志文件的代码,但是在事务提交之后:-
<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>
我不知道如何拆分它以便我可以显示日志文件,然后,如果没有任何更新错误,则提交事务。
请问有人有什么好主意可以帮忙吗?
【问题讨论】:
-
管理员/版主请关闭或删除此问题,因为似乎没有合理的解决方案
标签: php jquery logging transactions commit