using php to compare mysql columns to SQL Server -


i have 2 databases, 1 online (mysql) , 1 in office (sql server) compare , update value different.

i using php connect sql server database , run query retrieve information, connecting mysql database running query. need compare 2 queries , update necessary.

is there somewhere can tips on how this, sketchy on php , struggling really.

this far have got-:

<?php $server = "**server**"; $user = "**user**"; $pass = "**password**"; $db = "**db**";  //connection database $dbhandle = mssql_connect($server, $user, $pass) or die("couldn't connect sql server on $server");   //select database work $selected = mssql_select_db($db, $dbhandle) or die("couldn't open database $db");   //declare sql statement query database $query = "select p.id, p.code, ps.onhand"; $query .= "from products p with(nolock)"; $query .= "inner join productstockonhanditems ps with(nolock)"; $query .= "on ps.productid = p.id"; $query .= "where ps.stocklocationid = 1";   //execute sql query , return records $get_offlineproduct2 = mssql_query($query);  mysql_connect("**host**", "**username**", "**password**") or die(mysql_error()); mysql_select_db("database_name") or die(mysql_error());  $get_onlineproducts = mysql_query(select w.ob_sku, w.quantity product_option_value w order ob_sku)  or die(mysql_error());  //close connection mssql_close($dbhandle);  ?> 

i looking compare value p.code w.ob_sku , whenever match copy value of ps.onhand w.quantity online database has correct quantities office database.

my question guess how close getting right? doing right way, don't want far , realise wasting time...

thanks!

you not need fetch record mysql, since want update it.

i this:

$query = 'select p.code, ps.onhand (...)';  // execute sql query , return result set // mssql_query() returns resource // must iterate (e.g.) mssql_fetch_array() $mssqlresult = mssql_query($query);   // connect mysql database mysql_connect("**host**", "**username**", "**password**") or die(mysql_error()); mysql_select_db("database_name") or die(mysql_error());  while ( $mssqlrow = mssql_fetch_array($mssqlresult) ) {     $mssqlcode = $mssqlrow['code'];     $mssqlonhand = $mssqlrow['onhand'];     mysql_query(         "update product_option_value set quantity = $mssqlonhand ob_sku = $mssqlcode"        // quotes may required around $mssqlcode depending on column type     ); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -