Import data from SQL Server 2000 to MYSQL5.1

Source: Internet
Author: User


Import data from SQL Server 2000 to MYSQL5.1. 1. in SQL Server 2000, right-click the database to be exported and choose> all tasks> export data. 2. In the displayed dialog box, select "Next ". ", in the DTS import/export wizard, select "Next" 3. In the next dialog box, change the purpose to "Text File". In the file name dialog box, find the name of the file to be exported, click "Next ". 4. In the displayed dialog box, select "Use a query item to specify the data to be transmitted" and click "Next ". 5. In the displayed dialog box, enter related query statements. (For example, select id, name, pwd from user) Click "analysis". If "SQL statement valid" is displayed, click Next. 6. In the select target file format dialog box, select the corresponding separator (generally comma) and text delimiter (generally double quotation marks {"}), if necessary, click "Convert format" (I have selected to change the type of all fields to varchar, so that you can set delimiter in PHP) www.2cto.com 7. Next-> next-> finish 8. If "one table is successfully copied from Microsoft SQL Server to Flat File" is displayed." The export from SQL Server 2000 is successful! PHP versions must be later than 5.0 <? Php $ mysqli = new mysqli ('localhost', 'root', '000000', 'Douglas '); // This place must be set to utf8 instead of UTF-8 or UTF-8, if it is not utf8, garbled characters will appear in the Data $ mysqli-> query ("set names utf8"); if ($ mysqli) {www.2cto.com $ fh = fopen ('user.txt ', 'R'); $ delimiter = ','; $ enclosure = '"'; while ($ line = fgetcsv ($ fh, 120000, $ delimiter, $ enclosure )) {$ id = $ line [0]; $ name = $ line [1]; // because the text file exported by SQL Server 2000 is GB2312, it must be converted to the same Cha as the table in MYSQL. Racter Set, of course, this location and according to the need, if the table's Character set is GBK, then the UTF-8 of this location must be GBK $ name = iconv ('gb2312', 'utf-8 ', $ name); $ pwd = $ line [2]; $ query = "insert into user (id, name, pwd) values ('$ id',' $ name ', '$ pwd') "; $ result = $ mysqli-> query ($ query);} fclose ($ fh); mysqli_close ();} else {echo "You can't connect! ";}?> Author: DouglasLau

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.