How does PHP import MSSQL data to MYSQL?

Source: Internet
Author: User
Tags mssql server
This article mainly introduces how PHP imports MSSQL data to MYSQL, and lists two instances to import MSSQL data to MYSQL. it is a very practical technique, it has some reference value. if you need it, you can refer to the following example to describe how PHP imports MSSQL data to MYSQL. Share it with you for your reference. The specific analysis is as follows:

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, I wrote an instance myself and copied an instance.

Example 1: The code is as follows:

The code is as follows:

<? Php
// 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
?>


Refer to code 2. the code is as follows:

The code is as follows:

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

I hope this article will help you with php programming.

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.