Access database Fast Migration applet to MySQL (ii)

Source: Internet
Author: User
Tags odbc access database mysql database
The following is the import.php source program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<style type=text/css>
BODY,TD,LI,DIV,P,PRE,A,B,H1,H2,H3,H4 {font-family:verdana;font-size:9pt;line-height:18px;color: #a00000}
</style>
<body bgcolor= #f0f0f0 topmargin=0 leftmargin=0 text= #a00000 >
<center>
<br>
<div style= "Font-size:24pt;font-family:times;font-weight:bold;color: #008000" >odbc--> MySQL Migrant</ Div>

&LT;HR size=1 color= #900000 >

?

$dbconnection = @mysql_connect ("Yourmysqlserver", "Mysqlaccount", "Mysqlpassword")

Or Die ("Can not connect to database server");

@mysql_select_db ("Yourdatabase")

Or Die ("<p style= ' font-size:9pt;font-family:verdana;color: #803333; Font-weight:bold ' >no database,</p>" ) ;


$conn = Odbc_connect ("task", "", "");

$fp = fopen ("Fdlist.txt", "R");

$table 1 = fgets ($FP, 200);

$FD 1 = fgets ($fp, 1024);

$table 2 = fgets ($FP, 200);

$FD 2 = fgets ($fp, 1024);


$query 1 = "select". $FD 1. "From". $table 1;

$query 2 = "Select". $FD 2. "From". $table 2. "Where 1=2";

$result = mysql_query ($query 2);

mysql_query ("Delete from". $table 2);

echo "Sql=". $query 1;

$recordsid = Odbc_exec ($conn, $query 1);

$idcounts = Odbc_num_fields ($RECORDSID);

$idcount 2 = mysql_num_fields ($result);

if ($idcounts!= $idcount 2)
Die ("The fields of two tables doesn ' t match");

echo "<table width=90% border=1 bordercolorlight= #000000 bordercolordark= cellpadding=3 #ffffff cellspacing=0>n" ;



echo "<tr align=center><td> n";

for ($i = 1; $i <= $idcounts; $i + +)

echo "N<td>". Odbc_field_name ($recordsid, $i);

$theno = 1;

echo "<tr>n";



while (Odbc_fetch_row ($recordsid)) {



$runsql = "INSERT INTO". $table 2. "(" . $FD 2. ") 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);

?>

</body>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Experienced netizens may have seen two small programs that may feel like in an Access database
The fields in each table are English words, fdlist.php a little superfluous, in fact here, my
The idea is that when migrating, you can easily delete some unused fields, just delete the corresponding fields in the fdlist.php makefile Fdlist.txt. It is very convenient, anyway, with these two small programs, I previously placed in access dozens of tables of data, 20 minutes all migrated, including the five table field changes.

Of course, although the two programs achieve my intended function, but to extend it to all people can be used to migrate the ODBC database to the MySQL database, and more convenient to use, there are some aspects can be improved, such as based on the structure of the ODBC table automatically set up a MySQL table, if not established, Give a step-by-step user to create a Table Wizard function, detect the source table and destination table data type differences ... And so on, however, my data migration task has been completed, such a program has lost half of the driving force, if you give me a little encouragement, I may make a more perfect procedure, spiritual encouragement also line, of course, the material on the better (hello!). Not tomatoes and banana skins).
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.