[英]Mysql update table column from one database to another
I am working on a script that updates from: 我正在研究一个脚本,该脚本的更新来源为:
tendesig_zink_production | tenesig_zink_production | euid0_hikashop_product |
euid0_hikashop_product | product_quantity
product_quantity
to: 至:
tendesig_zink_dev | tenesig_zink_dev | euid0_hikashop_product |
euid0_hikashop_product | product_quantity
product_quantity
I have to do this because our inventory numbers are stored on the production instance. 我必须这样做,因为我们的库存编号存储在生产实例上。 so before pushing a new version from our dev instance i have to update the dev's inventories from production prior to the push.
因此,在从我们的开发人员实例推送新版本之前,我必须在推送之前从生产中更新开发人员的库存。 I am a lot rusty with my mySQL, this is what i have so far I need to know what the proper query would be though.
我对mySQL感到非常生锈,到目前为止,这是我需要知道的正确查询内容。
<?php
$host1="localhost"; // destination
$base1="tendesig_zink_dev";
$user1="tendesig_zink";
$password1="1,&#GZAWiB5z";
$host2="localhost"; //source
$base2="tendesig_zink_production";
$user2="tendesig_zink";
$password2="1,&#GZAWiB5z";
$conection1 = @mysql_connect($host1, $user1, $password1)
or die("Error reaching destination<br>".mysql_error()." nr eroare: ".mysql_errno());
print "Succesfuly connected 1! <br>";
$Db1 = @mysql_select_db($base1, $conection1)
or die("Error reaching destination database:<br>" . mysql_error(). "<br>" . mysql_errno());
print "Database1 reached!<br>";
$conection2 = @mysql_connect($host2, $user2, $password2)
or die("Error reaching source<br>".mysql_error()." nr eroare: ".mysql_errno());
print "Succesfuly connected 2!<br>";
$Db2 = @mysql_select_db($base2, $conection2)
or die("Error reaching source database:<br>" . mysql_error(). "<br>" . mysql_errno());
print "Database2 reached!!<br>";
$query = 'create table destination_table select * from second_database.source_table';
//echo "<br>".$query."<br>";
$result2 = mysql_query($query2, $conection1) or die('Query failed: ' . mysql_error().'||'.mysql_errno());
mysql_close($conection1);
mysql_close($conection2);
?>
Your query is wrong. 您的查询是错误的。 You want to do something like this:
您想做这样的事情:
CREATE TABLE destination_database.destination_table LIKE source_database.source_table
Then run this: 然后运行:
INSERT INTO destination_database.destination_table
SELECT * FROM source_database.source_table
In (untested) PHP code: 在(未经测试的)PHP代码中:
$create_query = 'CREATE TABLE destination_database.destination_table LIKE source_database.source_table';
$result = mysql_query($create_query, $conection1) or die('Query failed: ' . mysql_error().'||'.mysql_errno());
$insert_query = 'INSERT INTO destination_database.destination_table SELECT * FROM source_database.source_table';
$result = mysql_query($insert_query , $conection1) or die('Query failed: ' . mysql_error().'||'.mysql_errno());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.