普通网友 2015-02-11 05:51
浏览 94

如何将特定行(查询输出)移动到其他服务器上的另一个数据库?

I have situation like I need to move several rows of data from table in my local database to a remote database. The situation is:

  • I have a php page through which a group can be created and employee data can be uploaded into that group.
  • Then users will choose a group and click a button to move data, I need to move data which related to that group to a database which is on some other remote machine.

that data may be varies from hundreds to several thousand hundreds. Using queries in PHP to select, then delete, then insert into remote machine will take too long time to do this process.

Expecting there could be a better solution for this, but don't know..

Could anybody suggest me how to do this.

  • 写回答

1条回答 默认 最新

  • drra6593 2015-02-11 06:54
    关注

    Hope I understand what you are trying to get at? I am amusing you know PHP. When the page loads query the first DB and use results to populate form fields. When the form is submitted you can than insert the data into the next DB. You can do this all from one page.

    Example query on page load

    include '../connect-db.php';
    $query = "SELECT * FROM `DB`
            WHERE id='".$mysqli->real_escape_string($_REQUEST['id'])."'
            limit 0,1";
    
    //execute the query
    $result = $mysqli->query( $query );
    
    //get the result
    $row = $result->fetch_assoc();
    
    //assign the result to certain variable so our html form will be filled up with values
    $id = $row['id'];
    $name = $row['name'];
    

    populated HTML Form

    <form action=# method='post' name=ra id=ra>
    <table>
        <tr>
        <th><h1 class='whatever'><?php echo $name;?></h1></th>
        </tr>
        <tr>
        <input type='hidden' name='action' value='update' /> 
                <input type='submit' value='Update' /></td></tr></table>
    

    Insert Query on submit

    if($action=='update' ){
    include '../connect-new-db.php';
    
    $query = "insert into `DB` 
        set
            `name` = '".$mysqli->real_escape_string($_POST['name'])."',
            `link` = '".$mysqli->real_escape_string($_POST['link'])."'";
    
    //execute the query
    if( $mysqli->query($query) ) {
    //if saving success
    echo "<h2>The data has been added.</h2>";
    }else{
    //if unable to create new record
    echo "<h2>There has been an error adding the data</h2>";
    }
    }
    

    Hope that Helps

    评论

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图