PHP import MSSQL data to MYSQL instance _ PHP Tutorial

Source: Internet
Author: User
Tags mssql server
PHP imports MSSQL data to a MYSQL instance. Recently, a previous asp website needs to be converted to php, but php is related to mysql and my asp and mssql, and mssql data needs to be imported to the mysql database, next I wrote a new one that needs to convert a previous asp website to php recently, but php and mysql, and my asp and mssql, as a result, mssql data needs to be imported to the mysql database. I have written an instance and copied an instance.

Instance 1

The code is as follows:

// Domestic PNR code connection
$ Hostname = "127.0.0.1"; // The IP address or name of the MSSQL server
$ Dbuser = "sa"; // account of the MSSQL server
$ 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. you can also write $ db = mssql_select_db ($ dbname, $ conn) here );*/
$ SQL =
"Select * from Sheet1 $"; // SQL statement
$ Data = mssql_query ($ SQL); // Set the queried value in the variable $ data
While ($ Arr = mssql_fetch_object ($ data) // The initial set of loops $ 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"); // account used to connect to the database and port number
Mysql_query ("set names 'gbk'", $ conn );
Mysql_select_db ("taojipiao2009", $ conn); // load the database
// $ SQL = "update internationcode set jp = '$ a' where Code =' $ code '";
$ SQL = "insert into internationcode (Airport, citycode, Chinesecityname, Chinesecityjp, english, countrycode, countryfullname, Chauname) values ('$ Airport', '$ citycode ', '$ chinesecityname',' $ Chinesecityjp ',' $ EN', '$ countrycode', '$ countryfullname', '$ chauname ')";
// Echo $ SQL ."
";
$ Result = mysql_query ($ SQL );
}
// Mssql_close ($ conn); // Close the database

?>

Reference Code 2,

The code is as follows:

$ 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 * from 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 ";
}

?>

...

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.