我遇到的情况是,我需要将本地数据库中的表中的几行数据移动到远程数据库。情况是:
- 我有一个php页面,通过它可以创建一个组和员工可以将数据上传到该组中
- 然后用户会选择一个组并单击一个按钮来移动数据,我需要将与该组相关的数据移动到其他远程机器上的数据库中
该数据可能从数百到数千数百不等。使用PHP中的查询进行选择,然后删除,然后插入到远程机器中,这一过程需要很长时间。
本以为会有更好的解决方案,但不知道。。
有人能建议我怎么做吗。
希望我明白你想说什么?我很有趣,你知道PHP。当页面加载时,查询第一个DB并使用结果填充表单字段。提交表单后,您可以将数据插入下一个数据库。你可以在一页纸上完成这一切。
页面加载的示例查询
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'];
填充的HTML表单
<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>
在提交时插入查询
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>";
}
}
希望对有所帮助