Quick Migration of ACCESS database to MySQL (2) _ MySQL

Source: Internet
Author: User
Htmlheadstyletypetextcssbody, td, li, div, p, pre, a, B, h1, h2, h3, h4 {font-family: verdana; font-size: 9pt; line-height: 18px; color: # a00000} styleheadbodybgcolor # f0f0f0topmargin0leftmargin0text # a00000centerbrdivstylefont-size: 2 Access


  
  
  
  
  
  
  

  

ODBC --> MySQL Migrant


  
  
  
     
$ Dbconnection = @ mysql_connect ("yourmysqlserver", "mysqlaccount", "mysqlpassword ")
    
Or die ("can not connect to database server ");
    
@ Mysql_select_db ("yourdatabase ")
         
Or die ("

No Database,

");
  
$ Conn = odbc_connect ("task ","","");
    
$ Fp = fopen ("fdlist.txt", "r ");
    
$ Table1 = fgets ($ fp, 200 );
  
$ Fd1 = fgets ($ fp, 1024 );
  
$ Table2 = fgets ($ fp, 200 );
  
$ Fd2 = fgets ($ fp, 1024 );
    
$ Query1 = "select". $ fd1. "from". $ table1;
  
$ Query2 = "select". $ fd2. "from". $ table2. "where 1 = 2 ";
    
$ Result = mysql_query ($ query2 );
    
Mysql_query ("delete from". $ table2 );
    
Echo "SQL =". $ query1;
    
$ Recordsid = odbc_exec ($ conn, $ query1 );
    
$ Idcounts = odbc_num_fields ($ recordsid );
    
$ Idcount2 = mysql_num_fields ($ result );
    
If ($ idcounts! = $ Idcount2)
Die ("The fields of two tables doesn't match ");
  
Echo"








































N ";  Echo" N ";    While (odbc_fetch_row ($ recordsid )){  $ Runsql = "insert into". $ table2. "(". $ fd2. ") values (";       For ($ I = 1; $ I <= $ idcounts; $ I ++ ){       $ Fdv = odbc_result ($ recordsid, $ I );                  If (mysql_field_type ($ result, $ i-1) = "string ")         $ Runsql. = "'". $ fdv ."',";Else$ Runsql. = $ fdv .",";           }  $ Runsql = substr ($ runsql, 0, strlen ($ runsql)-1 );  $ Runsql. = ")";  Mysql_query ($ runsql );  $ Theno ++;}     Echo "Total Convert:". $ theno --;     Odbc_close ($ conn );  ?>        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Delete the corresponding field in the deleted statement. It is quite convenient. anyway, with these two applets, the data I previously stored in dozens of tables in ACCESS has been fully migrated in 20 minutes, the modification includes four or five table fields.  Of course, although the two programs have achieved my intended functions, they need to be expanded to allow everyone to migrate the ODBC database to the MySQL database, which is more convenient to use, there are also some improvements. for example, the MySQL table is automatically created based on the structure of the ODBC table. if the MySQL table cannot be created, the wizard function of table creation is provided step by step; check the differences between the source table and target table data types... wait, but my data migration task has been completed, and this program has lost half of the motive power. if you give me some encouragement, I may make a more perfect program and encourage myself mentally. of course, material is better (Hello! Not a tomato or banana peel ).
N ";
    
For ($ I = 1; $ I <= $ idcounts; $ I ++)
    
Echo "n
". Odbc_field_name ($ recordsid, $ I );
    
$ Theno = 1;
    
Echo"

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.