php将结果输入到数组并插入另一个数据库 [英] php getting results in to array and insert to another db

查看:110
本文介绍了php将结果输入到数组并插入另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用php在ms sql server中记录一些记录,我需要将那些

插入到mysql数据库表中。



I am geeting some records from ms sql server using php and I need to insert those
in to mysql database table.

 <?php
// create connection
$connection = mssql_connect("server-ip","user-name","password");

// test connection
if (!$connection) {
echo "Couldn''t make a connection!";
exit;
}

// select database
$db = mssql_select_db("db-name", $connection);

// test selection
if (!$db) {
echo "Couldn''t select database!";
exit;
}

// create SQL statement
$sql = "SELECT * from DBTable";

// execute SQL query and get result
$sql_result = mssql_query($sql,$connection);

// start results formatting
echo "<TABLE BORDER=1>";
echo "<TR><TH>Product No</TH><TH>Product Name</TH>";

// format results by row
while ($row = mssql_fetch_array($sql_result)) {
$po_no = $row["PNumber"];
$po_name = $row["PName"];
echo "<TR><TD>$po_no</TD></TR>";
echo "<TR><TD>$po_name</TD></TR>";

//Here I need to write code to insert these details in to
//my sql database.Is this way is correct?
// Section My SQL

$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die(''Could not connect: '' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO mysqlProducts (ProductNo,ProductName)
VALUES ($po_no,$po_name)");


mysql_close($con);

}

echo "</TABLE>";

// free resources and close connection
mssql_free_result($sql_result);
mssql_close($connection);

?> 





在这里,我需要编写代码将这些细节插入到我的sql数据库中的
。就这样是正确的?请看部分

//部分我的SQL



谢谢



Here I need to write code to insert these details in to
my sql database.Is this way is correct? please see the section
// Section My SQL

Thanks

推荐答案

connection = mssql_connect(server-ip,user-name,password);

//测试连接
if(!
connection = mssql_connect("server-ip","user-name","password"); // test connection if (!


connection){
echo无法建立连接!;
退出;
}

//选择数据库
connection) { echo "Couldn''t make a connection!"; exit; } // select database


db = mssql_select_db(db-name,
db = mssql_select_db("db-name",


这篇关于php将结果输入到数组并插入另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆