How to add an ODBC driver to a MAMP environment?

I am working on what was created on a PC using php and ms access database. When I port the application to my MAMP environment, I get

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

line 37 is as follows:

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

It seems that odbc is not compiled into the MAMP version of PHP (5). I also tried using PDO and got similar errors.

Does anyone know how to fix this?

+1
php ms-access mamp
source share
1 answer

You will need to add an ODBC driver to your computer, for example Actual ODBC , that is, if your version of PHP was executed with any ODBC functions in which it should be, but if not, you will need to install another version with the appropriate support. I was fortunate enough to use MacPorts to install PHP. But keep in mind that there are still some functions that may arise due to the fact that you have to write wrappers for these functions as follows:

  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); } } } 
+3
source share

All Articles