PHP implementation SQL Server data import MySQL database (example)

Source: Internet
Author: User
  1. Connecting to a SQL Server database
  2. $conn =mssql_connect ("localhost", "sa", "" "); Server name, user name, password
  3. mssql_select_db ("Db_database06", $conn); Connecting the Table_book Database
  4. Connect to MySQL Database
  5. $id =mysql_connect ("localhost", "root", "123456"); Local server localhost, user name root, password root
  6. mysql_select_db ("Db_database06", $id);
  7. mysql_query ("Set names gb2312"); Connecting the Shop_book Database
  8. Querying all the contents of a data table book from a 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 content of the output
  14. $author = $msrow [author];
  15. $bookconcern = $msrow [Bookconcern];
  16. ?>
  17. Exporting the contents of a SQL Server data table
    Name Author Bookconcern
  18. if ($Submit 2==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 "Import succeeded!!";
  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. Data that was successfully imported
    Name Author Bookconcern
Copy Code
  • 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.