PHP imports MSSQL data into MYSQL instance_PHP tutorial
WBOYOriginal
2016-07-13 17:06:43969browse
Recently I need to convert a previous ASP website into PHP, but PHP is with mysql and my asp is with mssql. As a result, I need to import the mssql data into the mysql database. I wrote an example myself below and copied it. An example is not bad.
//Domestic PNR code connection
$hostname="127.0.0.1"; //MSSQL server IP address or server name
$dbuser="sa"; //MSSQL server account
$dbpasswd="sa"; //MSSQL server password
$dbname="aa"; //Database name
$conn = mssql_connect($hostname,$dbuser,$dbpasswd); //Connect to MSSQL
mssql_select_db($dbname); /*Connect to the database to be accessed. This can also be written as $db=mssql_select_db($dbname,$conn); */
$sql =
"select * from Sheet1$"; //sql statement
$data = mssql_query($sql); //Collect the query value in the variable $data
while($Arr = mssql_fetch_object($data)) //Loop the initial collection $Arr
代码如下
复制代码
$mssql_link = mssql_connect($db_host,$db_msuser,$db_mspass) or
die("mssql数据库连接失败");
mssql_select_db($db_msname,$mssql_link);
$mysql_link = mysql_connect($db_myhost,$db_myuser,$db_mypass) or die("mysql数据库连接失败".mysql_error());
mysql_select_db($db_myname,$mysql_link);
$msquery = mssql_query("select top 1 * from buyok_produc",$mssql_link);
$sql =
"insert into `buyok_produc` ($cols) values $vars";
echo $sql;
$aa=mysql_query($sql, $mysql_link);
if ($aa){
echo "successfully";
}else{
echo "failed";
}
?>
{
$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");//Account and port number to connect to the database
mysql_query("SET NAMES ‘GBK’",$conn);
mysql_select_db("taojipiao2009",$conn);//Load database
//$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); //Close the database
?>
Reference code 2,
http://www.bkjia.com/PHPjc/630675.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630675.htmlTechArticleRecently I need to convert a previous asp website to php, but php is with mysql and my asp is with mssql Yes, the result is that the mssql data needs to be imported into the mysql database. I wrote one myself below...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn