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, has some reference value and needs
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, has some reference value and needs
This example describes 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.
,