為此我只好花了點時間寫了兩個小程序,用于將ACCESS數(shù)據(jù)庫的內(nèi)容向MySQL遷移,經(jīng)使用,效果還不錯,特在此寫出奉獻給各位一試或評判。
先概述一下使用方法,
1,將ACCESS的數(shù)據(jù)庫建立一個"system DSN";
2,根據(jù)ACCESS數(shù)據(jù)庫中各表的名稱,在MySQL中建立相應(yīng)的各個空表;
3,運行fdlist.php;
4,運行import.php;
5,每運行一次3,4步可遷移一個表,然后修改fdlist.php中的ACCESS源表名和MySQL中的目標表名,再運行3,4步,直至遷移所有的表,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以下為 fdlist.php源程序
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$dbconnection = @mysql_connect("yourmysqlserver", "mysqlaccount", "mysqlpassword")
or die ("can not connect to database server");
@mysql_select_db("yourdatabase")
or die(" ") ;
$odbc_table = "youroriginaltable" ; // The original table name in your ODBC database
$mysql_table = "yournewtable" ; // The new table name in your Mysql Database.
?>
$conn = odbc_connect("task", "", "");
$odbc_query = "select * from " . $odbc_table . " where 1=2";
$recordsid = odbc_exec($conn, $odbc_query);
$idcounts = odbc_num_fields( $recordsid ) ;
$fdlist1 = "" ;
for ( $i = 1 ; $i <= $idcounts ; $i ++)
$fdlist1 .= odbc_field_name($recordsid,$i)."," ;
echo "
Fd1 = " . $fdlist1 ;
$fdlist1 = substr($fdlist1,0,strlen($fdlist1)-1) ;
$fdlist2 = "" ;
$sqlquery = "select * from " . $mysql_table . " where 1=2 " ;
$records2 = mysql_query ($sqlquery) ;
$idcount2 = mysql_num_fields ( $records2 ) ;
for ( $i = 0 ; $i < $idcount2 ; $i++)
$fdlist2 .= mysql_field_name($records2,$i )."," ;
echo "
FD2 = " . $fdlist2 ;
$fdlist2 = substr($fdlist2,0,strlen($fdlist2)-1) ;
$fp = fopen ("fdlist.txt","w") ;
fwrite ($fp,$ctable) ;
fwrite ($fp,"n");
fwrite ($fp,$fdlist1) ;
fwrite ($fp,"n");
fwrite ($fp,$etable) ;
fwrite ($fp,"n") ;
fwrite ($fp,$fdlist2) ;
fclose($fp) ;
odbc_close($conn);
if ( $idcount2 != $idcounts ) {
echo "