2008-10-21 32 views
1

我正在使用php和ms訪問數據庫建立在PC設置上的東西。當我端口應用到我的MAMP環境,我得到如何將一個ODBC驅動程序添加到MAMP環境?

Fatal error: Call to undefined function odbc_connect() in /path/to/index.php on line 37 

線37個看起來像這樣:

return odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=myfile.mdb", 
"ADODB.Connection", "", "SQL_CUR_USE_ODBC"); 

好像ODBC是不會被編譯到PHP的MAMP版本(5)。我也嘗試使用PDO,並得到類似的錯誤。

任何人都知道如何解決這個問題?

+0

儘管MS採用了「Microsoft Access驅動程序」爲ODBC的名字的事實Jet數據驅動程序,你根本不使用Access,只有Jet。我希望他們不要這樣命名,因爲這會拯救一個混亂的世界。 – 2008-10-24 03:35:08

回答

3

您將需要爲您的機器添加一個ODBC驅動程序,如Actual ODBC,也就是說,如果您的PHP版本具有任何ODBC功能,應該有,但如果不是,則需要安裝不同版本適當的支持。我使用MacPorts來安裝PHP的時候運氣不錯。但請注意,仍有一些功能丟失,你可以指望你得寫這些功能,像這樣的包裝:

if(!function_exists("odbc_fetch_array")) 
    { 
    function odbc_fetch_array($aResult,$anAssoc=false) 
    { 
     # Out of rows? Pass back false! 
     if(!odbc_fetch_row($aResult)) return false; 

     $theRow = array(); 

      # Build up array 
     $theNumFields = odbc_num_fields($aResult); 
     $theLimit = $theNumFields+1; 
      for($i=1; $i<$theLimit; $i++) 
      { 
      # WARNING: Starts our index at 0, unlike standard ODBC which starts at 1 
       $theRow[odbc_field_name($aResult, $i)] = odbc_result($aResult, $i); 
       if(!$anAssoc) $theRow[$i-1] = $theRow[odbc_field_name($aResult, $i)]; 
     } 
     return $theRow; 
    } 
    } 

    if(!function_exists("odbc_fetch_assoc")) 
    { 
    function odbc_fetch_assoc($aResult) 
    { 
     if (DIRECTORY_SEPARATOR == '/') // call local function on MACs 
     { 
      return odbc_fetch_array($aResult,true); 
     } 
     else // call built in function on Windows 
     { 
      return odbc_fetch_array($aResult); 
     } 
    } 
    }