PHP imports MSSQL data into MySQL instance

Source: Internet
Author: User
Tags mssql mssql server vars mysql database port number

Instance One

The code is as follows Copy Code

<?php
PNR code connection in China
$hostname = "127.0.0.1"; The IP address of the MSSQL server or the name of the server
$dbuser = "sa"; The account number of the MSSQL server
$DBPASSWD = "sa"; The password for the MSSQL server
$dbname = "AA"; Name of the database

$conn = Mssql_connect ($hostname, $dbuser, $DBPASSWD); Connecting MSSQL
mssql_select_db ($dbname); /* Connection to access the database can also be written here $db =mssql_select_db ($dbname, $conn); */
$sql =
"SELECT * from sheet1$"; SQL statement
$data = Mssql_query ($sql); Set the value of the query in the variable $data
while ($ARR = Mssql_fetch_object ($data))//loop initial set $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");//Connect the database's account number and port number
mysql_query ("SET NAMES ' GBK '", $conn);
mysql_select_db ("taojipiao2009", $conn);//Loading 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. " <br> ";
$result =mysql_query ($sql);
}
Mssql_close ($conn); Close Database

?>

Reference code Two,

The code is as follows Copy Code

<?php

$mssql _link = Mssql_connect ($db _host, $db _msuser, $db _mspass) or
Die ("MSSQL database connection failed");

mssql_select_db ($db _msname, $mssql _link);

$mysql _link = mysql_connect ($db _myhost, $db _myuser, $db _mypass) or Die ("MySQL database connection failed". Mysql_error ());

mysql_select_db ($db _myname, $mysql _link);

$msquery = Mssql_query ("SELECT top 1 * buyok_produc", $mssql _link);

$vars = ";
$vals = ";
$cols = ";

while ($row = Mssql_fetch_array ($msquery, $mssql _link)) {
$vals = ";
foreach ($row as $key => $values) {
$cols. = ($cols = = "? $key: ', '. $key);
$vals. = ($vals = = "?". $values. ', ': '. $values. ';
Echo $vals;
}
$vars. = ($vars = = "? ('. $vals. ') ' : ', ('. $vals. ');
}

$sql =
"INSERT INTO ' buyok_produc ' ($cols) values $vars";

Echo $sql;

$aa =mysql_query ($sql, $mysql _link);

if ($AA) {
echo "successfully";
}else{
echo "Failed";
}

?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.