2013-04-10 75 views
1

MDB格式是否有任何PHP类提供给mysql数据库转换为MDB格式我如何导出/转换MySQL数据库使用PHP

我只是想在MS Access格式

采取备份我的MySQL数据库
+0

你使用'GUI应用程序数据库'或'控制台应用程序数据库'吗? – Ranjith 2013-04-10 05:07:06

+0

你有phpmyadmin吗? – 2013-04-10 05:11:19

+0

Deepanshu:是啊phpmyadmin – sree 2013-04-10 05:20:29

回答

2

如果你问一个图书馆,有一个存在于here

您可以使用COM来访问MDB司机,还有位于phpclasses一个简单的类充当这样的包装,你可以要么用它来获得灵感,要么直接移植它,无论哪种方式都是完全可能的:

这里是类:

<?php  
class mdb 
{ 
    var $RS = 0; 
    var $ADODB = 0; 

    var $RecordsAffected; 

    var $strProvider = 'Provider=Microsoft.Jet.OLEDB.4.0'; 
    var $strMode  = 'Mode=ReadWrite'; 
    var $strPSI  = 'Persist Security Info=False'; 
    var $strDataSource = ''; 
    var $strConn  = ''; 
    var $strRealPath = ''; 

    var $recordcount = 0; 
    var $ok = false; 


    /** 
    * Constructor needs path to .mdb file 
    * 
    * @param string $dsn = path to *.mdb file 
    * @return boolean success 
    */ 
    function mdb($dsn='Please enter DataSource!') 
    { 
    $this->strRealPath = realpath($dsn); 
    if(strlen($this->strRealPath) > 0) 
    { 
     $this->strDataSource = 'Data Source='.$this->strRealPath; 
     $result = true; 
    } 
    else 
    { 
     echo "<br>mdb::mdb() File not found $dsn<br>"; 
     $result = false; 
    } 

    $this->RecordsAffected = new VARIANT(); 

    $this->open(); 

    } // eof constructor mdb() 


    function open() 
    { 
    if(strlen($this->strRealPath) > 0) 
    { 

     $this->strConn = 
     $this->strProvider.';'. 
     $this->strDataSource.';'. 
     $this->strMode.';'. 
     $this->strPSI; 

     $this->ADODB = new COM('ADODB.Connection'); 

     if($this->ADODB) 
     { 
     $this->ADODB->open($this->strConn); 

     $result = true; 
     } 
     else 
     { 
     echo '<br>mdb::open() ERROR with ADODB.Connection<br>'.$this->strConn; 
     $result = false; 
     } 
    } 

    $this->ok = $result; 

    return $result; 
    } // eof open() 


    /** 
    * Execute SQL-Statement 
    * @param string $strSQL = sql statement 
    * @param boolean $getrecordcount = true when a record count is wanted 
    */ 
    function execute($strSQL, $getrecordcount = false) 
    { 

    $this->RS = $this->ADODB->execute($strSQL, &$this->RecordsAffected); 

    if($getrecordcount == true) 
    { 

     $this->RS->MoveFirst(); 
     $this->recordcount = 0; 

     # brute force loop 
     while($this->RS->EOF == false) 
     { 
     $this->recordcount++; 
     $this->RS->MoveNext(); 
     } 
     $this->RS->MoveFirst(); 

    } 


    } // eof execute() 

    function eof() 
    { 
    return $this->RS->EOF; 
    } // eof eof() 

    function movenext() 
    { 
    $this->RS->MoveNext(); 
    } // eof movenext() 

    function movefirst() 
    { 
    $this->RS->MoveFirst(); 
    } // eof movefirst() 

    function close() 
    { 

    @$this->RS->Close(); // Generates a warning when without "@" 
    $this->RS=null; 

    @$this->ADODB->Close(); 
    $this->ADODB=null; 
    } // eof close() 

    function fieldvalue($fieldname) 
    { 
    return $this->RS->Fields[$fieldname]->value; 
    } // eof fieldvalue() 

    function fieldname($fieldnumber) 
    { 
    return $this->RS->Fields[$fieldnumber]->name; 
    } // eof fieldname() 

    function fieldcount() 
    { 
    return $this->RS->Fields->Count; 
    } // eof fieldcount() 

} // eoc mdb 
?> 

和示例:

include 'class_mdb.php'; 

$mdb = new mdb('mymdbfile.mdb'); // your own mdb filename required 
$mdb->execute('select * from table'); // your own table in the mdb file 

# 
# first example: using fieldnames 
# 

while(!$mdb->eof()) 
{ 
    echo $mdb->fieldvalue('description'); // using your own fields name 
    echo ' = '; 
    echo $mdb->fieldvalue(1); // using the fields fieldnumber 
    echo '<br>'; 
    $mdb->movenext(); 
} 

echo '<br><hr><br>'; 

# 
# Going back to the first recordset for the second example 
# 
$mdb->movefirst(); 

# 
# This works, too: Make each Field an object. The values change 
# when the data pointer advances with movenext(). 
# 
$url = $mdb->RS->Fields(1); 
$bez = $mdb->RS->Fields(2); 
$kat = $mdb->RS->Fields(3); 

while(!$mdb->eof()) 
{ 
    # works! 
    echo $bez->value; 
    echo ' = '; 
    echo $url->value; 
    echo '<br>'; 
    $mdb->movenext(); 
} 

$mdb->close(); 

refernce post

更新

现在,如果你可以创建mdb文件,您可以导出有你的MySQL数据库。

相关问题