Home » Php » macos – Enabling PHP pdo_odbc extension on a Mac OSX

macos – Enabling PHP pdo_odbc extension on a Mac OSX

Posted by: admin July 12, 2020 Leave a comment


I am trying to get the pdo_odbc extension for PHP enabled on my Mac which is running PHP 5.3 Here is what i did to try to get it to work:

  1. I installed UnixODBC with brew

    $ brew install unixodbc
  2. Downloaded the source for PHP 5.3.8. In the terminal I navigated to the pdo_odbc folder. Then did the following.

    $ phpize
    $ ./configure --with-pdo-odbc=unixODBC
    $ make

    There was an error.

    /Users/todd/Downloads/php-5.3.8/ext/pdo_odbc/pdo_odbc.c:43: error: ‘ZEND_MOD_END’ undeclared here (not in a function)
    /Users/todd/Downloads/php-5.3.8/ext/pdo_odbc/pdo_odbc.c: In function ‘zm_startup_pdo_odbc’:
    /Users/todd/Downloads/php-5.3.8/ext/pdo_odbc/pdo_odbc.c:135: warning: cast to pointer from integer of different size

    Based on some blogs I replaced ZEND_MOD_END with {NULL,NUll, NULL} and ran make again. This time it complied.

  3. Then I ran “sudo make install”
    and that installed the extension in the right place. I modifed php.ini to enable it. And it shows up in phpInfo()

So far so good. But when I start running simple tests I get errors about every other try

php(20048,0x7fff796f1960) malloc: *** mmap(size=2977160837258543104) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called throwing an exceptionAbort trap: 6

This was thrown, when i tried to execute this code:


   $dsn = 'odbc:Driver={FileMaker ODBC};Server=localhost;Database=CalDAV;';
   $pdo = new PDO($dsn, "odbc", "odbc");

   $sql = "SELECT * From Users Where id = 2";
   $r = $pdo->query($sql);

   $sql = "SELECT * From Users Where id = ?";
   $stmt = $pdo->prepare($sql);


this line causes the exception.


Does anyone have any experience getting pdo_odbc to work on the Mac. I would really like to get this extension working. Suggestions ?

How to&Answers:

Perhaps worth noting that Apple chose iODBC (over UnixODBC) for Mac OS X and bundled it in starting with Jaguar (10.2). You should get the latest update from the iodbc.org site, because Apple has never kept up with the official project patches. I recommend installing both the Frameworks and such, and applying the separate patches to the Apple-bundled headers and dylibs.

Past malloc issues associated with UnixODBC have been resolved by shifting to iODBC. I do not know that this will be the case for you, but it seems a small investment to try.

(ObDisclaimer: I work for OpenLink Software; we maintain and support the iODBC project. I personally gain nothing from your pursuing this option.)


Have you checked your php.ini (or equivalent) to see if your ‘memory_limit’ setting is high enough?

Error 12 appears to be related to memory exhaustion, but I’m not sure if it’s related to a run-away loop in the tests you are running, or simply too many very large allocations. Check what a phpinfo() dump says about your current ‘memory_limit’ setting and then up it to see if that corrects the error.

See also: http://www.php.net/manual/en/ini.core.php#ini.memory-limit


I personally prefer MacPorts, although I think most folks prefer Fink. The easiest way to get more feature-complete versions of standard unix packages for OSX is to use either MacPorts or Fink.

Locate the php.ini file on your Mac (/etc/php.ini)
Replace all instances of /var/mysql/mysql.sock to /tmp/mysql.sock
Save the file and restart Apache.


I’m using VirtualBox with a Ubuntu Server Distro on my MacBook.

Since I’ve noticed that one OSX update can ruin your configuration.

  • VirtualBox (20GB VDI)
  • Ubuntu Linux-Server (with an host-only adapter)
  • LAMP (Apache, MySQL & PHP)
  • Samba (To manage my web-projects)

Works great for development and you don’t need to worry about dependencies being ported properly!