简体   繁体   English

SQL查询:数据从一个数据库传输到另一个数据库

[英]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">&times;</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">&times;</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">&times;</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.

相关问题 使用php和json将数据从一个数据库传输到另一个数据库 - Data transfer from one database to another using php and json 使用PHP从一个SQL数据库中获取数据并将其插入到另一个SQL数据库中 - Using PHP to take data from one SQL database and inserting it into another 如何使用 laravel 迁移将数据从一个表传输到另一个数据库表 - How can i transfer data from one table to another database table using laravel migration PHP SQL:如何将数据从一个html表单保存到多个数据库,或者如何自动将数据从一个数据库复制到另一个数据库 - PHP SQL : How to save data to multiple database from one html form OR how to copy data from one database to another database automatically PHP - 将数据从表传输到数据库中的另一个表 - PHP - Transfer Data from table to another within a database 将数据从表传输到同一数据库中的另一个表 - Transfer data from table to another table in same database 如何在Laravel中将一对多数据从数据库传输到模板? - How to transfer one-to-many data from a database to a template in Laravel? PHP SQL:我无法将数据从一个表传输到数据库 sql 中的用户界面按钮 sql 文件中的 UI 按钮 - PHP SQL: I cant transfer data from 1 table to another table in database sql using UI button in php file 将数据从一个MYSQL数据库迁移到另一个数据库 - migrate data from one MYSQL database to another 在mysql中将数据从一个数据库插入另一个数据库 - Insert data from one database to another in mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM