我需要编写一个脚本,该脚本将从两列中获取值,并使用它们来更新我在另一个数据库中创建的视图中的列。在第一个数据库中,我有sku和qty以及视图。
这是我的代码:
$server = 'localhost';
$user = 'invodata';
$pass = 'Abcd1234!1';
$dbname = 'tboinvodata';
$con = mysql_connect($server, $user, $pass) or die("Can't connect");
mysql_select_db("tboinvodata") or die(mysql_error());
$result = mysql_query("SELECT item, onhand FROM immaster"); <- this is getting the values from the columns in the first data base
$server = 'localhost';<-setting up my second connection to other database
$user = 'tbo';
$pass = 'Abcd1234!1';
$dbname = 'i187358_mage1';
$con = mysql_connect($server, $user, $pass) or die("Can't connect");
mysql_select_db("i187358_mage1") or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {<-this gets the array from other database
UPDATE qtyview SET qty = $row["onhand"] WHERE sku = item;<- this should update the necessary columns "sku" is used in my view and "item" is used in the first data base I use this so the proper rows in the other columns get updated.
}
?>
我真的不确定我做错了什么我虽然很新。
答案 0 :(得分:0)
您可以多次拨打mysql_connect()
并像这样使用它们。
首先连接两个MYSQL USER
$con1 = mysql_connect($server, $user, $pass);
$con2 = mysql_connect($server, $user, $pass, true);
然后使用不同的DATABASE
mysql_select_db('firstdatabase', $con1);
mysql_select_db('seconddatabase', $con2);
然后从firstdatabase
这样查询
mysql_query('select * from views', $con1);
从seconddatabase
mysql_query('select * from views', $con2);
此代码未经我测试......但我认为它对您有用.. :)。