当前位置: 首页 > 图文教程 > 数据库 > MSSQL > ACCESS数据库向MySQL快速迁移小程序(二)

MSSQL
MSSQL 数据库备份和还原的几种方法 图文教程
GridView自定义分页的四种存储过程
sqlserver 中charindex/patindex/like 的比较
SQL2005 大数据量检索的分页
MSSQL2005 INSERT,UPDATE,DELETE 之OUTPUT子句使用实例
MSSQL 字符段分段更新
SQLServer2005中的SQLCMD工具使用
Sql server2005 优化查询速度50个方法小结
SQL2005 四个排名函数(row_number、rank、dense_rank和ntile)的比较
sql2005 数据同步方法
配置 SQLServer2005 以允许远程连接
安装SQL2005 29506错误码的解决方案
SQL Server 2008的升级和部署问题
SQL Server教程:读取第三方数据库的数据
用Trigger规范insert, update的值

MSSQL 中的 ACCESS数据库向MySQL快速迁移小程序(二)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 32 ::
收藏到网摘: n/a

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以下为 import.php 源程序
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<html>
<head>
<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>
</head>
<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>

<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") ;
     
    $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 "<table width=90% border=1 bordercolorlight=#000000 bordercolordark=#ffffff cellpadding=3 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) )  {