Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling PHP pdo_odbc extension on a Mac OSX

Tags:

php

macos

pdo

odbc

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:

<?php

   $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);
   print_r($r->fetch(PDO::FETCH_ASSOC));

   $sql = "SELECT * From Users Where id = ?";
   $stmt = $pdo->prepare($sql);
   $stmt->execute(array(2));
   print_r($stmt->fetch(PDO::FETCH_ASSOC));

?>

this line causes the exception.

$stmt->execute(array(2));

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

like image 738
toddgeist Avatar asked Mar 31 '12 19:03

toddgeist


People also ask

Does macOS have PHP?

PHP is bundled with macOS since macOS X (10.0.

Where is my PHP on Mac?

Set the php. ini location or use the default A typical default location on macOS is /usr/local/php/php.


1 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.)

like image 116
TallTed Avatar answered Oct 05 '22 19:10

TallTed