PHP to import MSSQL data into the MySQL method, MSSQL data import _php Tutorial

Source: Internet
Author: User
Tags mssql server vars

PHP to import MSSQL data into the MySQL method, MSSQL data import


The example in this paper describes how PHP imports MSSQL data into MySQL. Share to everyone for your reference. The specific analysis is as follows:

Recently need to convert a previous ASP Web site to PHP, but PHP is with MySQL and my ASP and MSSQL, the results will need to import MSSQL data into the MySQL database, the following I wrote an example and copied an example is good.

Example one, the code is as follows:
Copy CodeThe code is as follows: <?php
Domestic PNR Code Connection
$hostname = "127.0.0.1"; The IP address or server name of the MSSQL server
$dbuser = "sa"; MSSQL Server's account number
$DBPASSWD = "sa"; The password of the MSSQL server
$dbname = "AA"; The name of the database

$conn = Mssql_connect ($hostname, $dbuser, $DBPASSWD); Connect MSSQL
mssql_select_db ($dbname); /* Connect the database to access it can also be written here $db =mssql_select_db ($dbname, $conn); */
$sql = "SELECT * from sheet1$"; SQL statements
$data = Mssql_query ($sql); Sets the value of the query to the variable $data
while ($ARR = Mssql_fetch_object ($data))//Loop Initial collection $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 number and port number connected 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
?>
Refer to code two for the following code:
Copy CodeThe 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 is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/933595.html www.bkjia.com true http://www.bkjia.com/PHPjc/933595.html techarticle PHP to the MSSQL data into the MySQL method, MSSQL data import examples of the introduction of the MSSQL data PHP to MySQL method. Share to everyone for your reference. The specific analysis is as follows: most ...

  • 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.