[英]SQL query : Data transfer from one database to another database
I am trying to transfer the required data from one database to another database using a button click . 我正在尝试通过单击按钮将所需的数据从一个数据库传输到另一个数据库。 The query which am using is working fine in localhost without any issue but while hosted in cpanel (online linux hosting) .. the data is not getting transfered to another database .
正在使用的查询在localhost中正常运行,没有任何问题,但是在cpanel中托管(在线linux托管)..数据未传输到另一个数据库。
I have rechecked each and every corner for database name password , user etc but could not solve the issue . 我已经重新检查了每个角落的数据库名称密码,用户等,但无法解决问题。
Html :- HTML:-
//When the button is clicked it opens up the modal (data-target=#approveMemberModal) //当单击按钮时,它会打开模态(data-target =#approveMemberModal)
<a type="button" class="btn btn-success" data-toggle="modal" data-target="#approveMemberModal" onclick="approveMember('.$row['id'].')"> <span class="glyphicon glyphicon-edit"></span> Approve</a></li>
//Approve Modal //批准模式
<div class="modal fade" tabindex="-1" role="dialog" id="approveMemberModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><span class="glyphicon glyphicon-trash"></span> Approve Member</h4>
</div>
<div class="modal-body">
<p>Do you really want to Approve ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="approveBtn">Yes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
//Once ApproveMemberModal opens up .. there will be two options "Close" and "Yes" .. "Yes" option have id="approveBtn" which is reference to call ajax when button is clicked. //一旦打开ApproveMemberModal ..将有两个选项“ Close”和“ Yes” ..“ Yes”选项具有id =“ approveBtn”,这是在单击按钮时调用ajax的引用。
//Ajax //阿贾克斯
function approveMember(id = null) {
if(id) {
// click on remove button
$("#approveBtn").unbind('click').bind('click', function() {
$.ajax({
url: 'php_action/approve.php',
type: 'post',
data: {member_id : id},
dataType: 'json',
success:function(response) {
if(response.success == true) {
$(".approveMessages").html('<div class="alert alert-success alert-dismissible" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+
'<strong> <span class="glyphicon glyphicon-ok-sign"></span> </strong>'+response.messages+
'</div>');
// refresh the table
manageMemberTable.ajax.reload(null, false);
// close the modal
$("#approveMemberModal").modal('hide');
} else {
$(".approveMessages").html('<div class="alert alert-warning alert-dismissible" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+
'<strong> <span class="glyphicon glyphicon-exclamation-sign"></span> </strong>'+response.messages+
'</div>');
}
}
});
}); // click remove btn
} else {
alert('Error: Refresh the page again');
}
}
//From Ajax it will call php file ie approve.php //从Ajax它将调用php文件,即approve.php
PHP PHP
<?php
require_once 'db_connectone.php';
require_once 'db_connecttwo.php';
$output = array('success' => false, 'messages' => array());
$memberId = $_POST['member_id'];
$sql = "INSERT INTO appsrx1a_one.candidate_tabletest (candid,mobile , secmobile) SELECT candid,mobile , secmobile FROM appsrx1a_one.candidate_tabletest WHERE id = {$memberId}";
$sqll="DELETE FROM appsrx1a_one.candidate_tabletest WHERE id = {$memberId}";
$query = $connect->query($sql);
$query = $connect->query($sqll);
if($query === TRUE) {
$output['success'] = true;
$output['messages'] = 'Successfully Approved';
} else {
$output['success'] = false;
$output['messages'] = 'Error while approving the member information';
}
// close database connection
$connect->close();
echo json_encode($output);
From the above php file db_connectone.php have database connection of first database and db_connecttwo.php have database connection of second database 从上面的php文件db_connectone.php具有第一个数据库的数据库连接,而db_connecttwo.php具有第二个数据库的数据库连接
The Below query will it will select data from database one ie (appsrx1a_one) and inserts into database two ie (appsrx1a_two.candidate_tabletest) 下面的查询将从数据库1中选择数据,即(appsrx1a_one)并将其插入数据库2中,即(appsrx1a_two.candidate_tabletest)
$sql = "INSERT INTO appsrx1a_two.candidate_tabletest (candid,mobile , secmobile) SELECT candid,mobile , secmobile FROM appsrx1a_one.candidate_tabletest WHERE id = {$memberId}";
Once it is transfered the below query deletes the data from database one ie (appsrx1a_one) 一旦传输完毕,下面的查询将从数据库1中删除数据,即(appsrx1a_one)
$sqll="DELETE FROM appsrx1a_one.candidate_tabletest WHERE id = {$memberId}";
All the above functionalies are working fine in localhost without any issue .. am facing this issue only in cpanel ... in error_log am not getting any error . 以上所有功能在localhost中都可以正常工作,没有任何问题..仅在cpanel中才遇到此问题... error_log中没有任何错误。
What might be the issue in this code . 这段代码可能是什么问题。 If the above method is wrong provide the proper method to this .
如果以上方法有误,请为此提供适当的方法。 Thanks
谢谢
Check the database name. 检查数据库名称。 cPanel creates the databases different using cpaneluser_dbname.
cPanel使用cpaneluser_dbname创建不同的数据库。 Check the database credentials like mysql user, password to be sure that the configure mysql user has access to the configured mysql database (you can allow permissions to a database to a specific mysql user using the cPanel web interface).
检查数据库凭据,例如mysql用户,密码,以确保配置的mysql用户可以访问配置的mysql数据库(您可以使用cPanel Web界面向特定的mysql用户授予对数据库的权限)。 If you have shell access you can try to run the script manually from a ssh console.
如果您具有外壳程序访问权限,则可以尝试从ssh控制台手动运行脚本。 You could modify the script an add debugging to it like printing the status at different stages in the script to check where exactly the script is, what's the last output of the last executed command
您可以修改脚本并对其添加调试,例如在脚本的不同阶段打印状态,以检查脚本的确切位置,最后执行的命令的最后输出是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.