我想在一个查询中将结果从MSSql Server复制到MySql
下面的代码为MSSql View中的SO_Numbber编写Fitch并获得结果我想将此结果一次性复制到MySql上的另一个表中
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="sales" method="post">
<!-- text input -->
<div class="form-group">
<label>
<input type="text" name="SO_Number"/>
</label>
</div>
<div class="box-footer">
<button type="Submit" name="Submit" id="Submit">Submit</button>
</div>
</form>
<?php
//connect to a DSN "myDSN"
$Connection = odbc_connect('SQL','sa','sa');
if ($Connection)
{
if (isset($_POST['SO_Number'])) {$SO_Number = $_POST['SO_Number'];}
if (isset($_POST['Submit']))
{ //the SQL statement that will query the database
$Query = "SELECT * FROM [test_eta].[dbo].[AAR1472] WHERE LPO_NO = $SO_Number";
//perform the query
$Result=odbc_exec($Connection, $Query);
echo "<table border='1'><tr>";
//print field name
$colName = odbc_num_fields($Result);
for ($j=1; $j<= $colName; $j++)
{
echo "<th>";
echo odbc_field_name ($Result, $j );
echo "</th>";
}
//fetch tha data from the database
while(odbc_fetch_row($Result))
{
echo "<tr>";
for($i=1;$i<=odbc_num_fields($Result);$i++)
{
echo "<td>";
echo odbc_result($Result,$i);
echo "</td>";
}
echo "</tr>";
}
echo "</td> </tr>";
echo "</table >";
//close the connection
odbc_close ($Connection);
}
}
else echo "odbc not connected";
?>