Import SQL server data into Mysql database using php (example)

Source: Internet
Author: User
Import SQL server data into Mysql database using php (example)

  1. // Connect to the SQL server database
  2. $ Conn = mssql_connect ("localhost", "sa", ""); // server name, user name, and password
  3. Mssql_select_db ("db_database06", $ conn); // connect to the table_book database
  4. // Connect to the mysql database
  5. $ Id = mysql_connect ("localhost", "root", "123456"); // localhost on the local server, root user name, and root password
  6. Mysql_select_db ("db_database06", $ id );
  7. Mysql_query ("set names gb2312"); // connect to the shop_book database
  8. // Query all the contents of the data table book from the SQL server database
  9. ?>
  10. SQL Server data import to MySQL database _ bbs.it-home.org
  11. $ Ms_query = mssql_query ("select * from $ db_database", $ conn );
  12. While ($ msrow = mssql_fetch_array ($ ms_query )){
  13. $ Name = $ msrow [name]; // set a variable for the output content
  14. $ Author = $ msrow [author];
  15. $ Bookconcern = $ msrow [bookconcern];
  16. ?>
  17. Export the content of an SQL Server Data table
    Name Author Bookconcern
  18. If ($ Submit2 = true ){
  19. $ Query = mysql_query ("insert into tb_book (name, author, bookconcern)
  20. Values ('$ name',' $ author', '$ bookconcern') ", $ id );
  21. }
  22. If ($ query = true ){
  23. Echo "imported successfully !! ";
  24. } Else {echo "import failed !! ";}
  25. ?>
  26. $ Query = mysql_query ("select * from tb_book ");
  27. If ($ query = true ){
  28. While ($ myrow = mysql_fetch_array ($ query )){
  29. ?>
  30. Imported data
    Name Author Bookconcern

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.