本文实例讲述了PHP把MSsql数据导入到MysqL的方法。分享给大家供大家参考。具体分析如下:
最近需要把一个以前的asp网站转换成PHP的,但PHP是与MysqL而我的asp与mssql的,结果就需要把mssql数据导入到MysqL数据库了,下面我自己写了一个实例还抄了一个实例都不错.
实例一,代码如下:
代码如下:
$conn = mssql_connect($hostname,$dbuser,$dbpasswd); //连接MSSQL
mssql_select_db($dbname); /连接要访问的数据库 这里也可以写做 $db=mssql_select_db($dbname,$conn); /
$sql = "select from Sheet1$"; //sql语句
$data = mssql_query($sql); //把查询的值集合在变量$data
while($Arr = mssql_fetch_object($data)) //循环初始的集合$Arr
{
$Airport=$Arr->Airport;
$citycode=$Arr->citycode;
$Chinesecityname=$Arr->Chinesecityname;
$Chinesecityjp=$Arr->Chinesecityjp;
$english=$Arr->english;
$countrycode=$Arr->countrycode;
$countryfullname=$Arr->countryfullname;
$Chauname=$Arr->Chauname;
//echo $code;
$conn=MysqL_connect("localhost","root","123456");//连接数据库的帐号和端口号
MysqL_query("SET NAMES 'GBK'",$conn);
MysqL_select_db("taojipiao2009",$conn);// 加载数据库
//$sql="update internationcode set jp='$aa' where Code='$Code'";
$sql="insert into internationcode(Airport,citycode,Chinesecityname,Chinesecityjp,english,countrycode,countryfullname,Chauname) values('$Airport','$citycode','$Chinesecityname','$Chinesecityjp','$english','$countrycode','$countryfullname','$Chauname')";
//echo $sql."
";
$result=MysqL_query($sql);
}
//mssql_close($conn); //关闭数据库
?>
mssql_select_db($dbname); /连接要访问的数据库 这里也可以写做 $db=mssql_select_db($dbname,$conn); /
$sql = "select from Sheet1$"; //sql语句
$data = mssql_query($sql); //把查询的值集合在变量$data
while($Arr = mssql_fetch_object($data)) //循环初始的集合$Arr
{
$Airport=$Arr->Airport;
$citycode=$Arr->citycode;
$Chinesecityname=$Arr->Chinesecityname;
$Chinesecityjp=$Arr->Chinesecityjp;
$english=$Arr->english;
$countrycode=$Arr->countrycode;
$countryfullname=$Arr->countryfullname;
$Chauname=$Arr->Chauname;
//echo $code;
$conn=MysqL_connect("localhost","root","123456");//连接数据库的帐号和端口号
MysqL_query("SET NAMES 'GBK'",$conn);
MysqL_select_db("taojipiao2009",$conn);// 加载数据库
//$sql="update internationcode set jp='$aa' where Code='$Code'";
$sql="insert into internationcode(Airport,citycode,Chinesecityname,Chinesecityjp,english,countrycode,countryfullname,Chauname) values('$Airport','$citycode','$Chinesecityname','$Chinesecityjp','$english','$countrycode','$countryfullname','$Chauname')";
//echo $sql."
";
$result=MysqL_query($sql);
}
//mssql_close($conn); //关闭数据库
?>
参考代码二,代码如下:
<div class="codetitle"><a style="CURSOR: pointer" data="61582" class="copybut" id="copybut61582" onclick="doCopy('code61582')"> 代码如下: