A few people have reported problems with trying to run PDO on OSX; I believe them to be general dynamic loading issues in the PHP build system itself. We'll try to resolve them for PHP 5.1. In the meantime, if you're on OSX and want to try PDO, then you can try building it statically; here's how:

Now we need to integrate the PDO extensions into the PHP source tree. Open up a terminal window and cd to where you've downloaded the sources.

   tar xjf php5-STABLE-latest.tar.bz2
   tar xzf PDO-0.2.2.tgz
   tar xzf PDO_SQLITE-0.2.2.tgz
   mv PDO-0.2.2 php5-STABLE-200502120730/ext/pdo
   mv PDO_SQLITE-0.2.2 php5-STABLE-200502120730/ext/pdo_sqlite
   cd php5-STABLE-200502120730
   rm configure
   ./buildconf --force

At this point, you're ready to build configure PHP. As I'm writing this, I'm testing things out on a G4 450MHz running OSX.2; it's not quite as fast as I'd like, so I'm going for a fairly minimal PHP install, skipping all the xml stuff and using only pdo and pdo sqlite. You should probably leave out the "--disable-all" option when you build it:

   ./configure --disable-all --enable-debug \\
          --prefix=/usr/local/php-5.0.4 \\
          --enable-cli --enable-pdo \\

Now, here's a tricky part. The build system in PHP 5.0.x doesn't know that PDO should be initialized before the PDO driver(s), so we need to edit two files to make that happen. For PHP 5.1, you won't need to do this step. Use your favourite editor to open up main/internal_functions.c. Find the part that looks like this:

    zend_module_entry *php_builtin_extensions[] = {

You need to change it so it looks like this instead:

    zend_module_entry *php_builtin_extensions[] = {

In other words, you need to make sure that the pdo_ptr line is listed before any other pdo_XXX_ptr line. Note that you will probably have a bunch of other extensions listed here; leave the order of those as they are; the important thing is that pdo comes before the other pdo lines.

Repeat this step for main/internal_functions_cli.c

Now you're ready to build:


And you're done. You can install this if you like, by running "make install"; it will land in the prefix you specified (if you copied me, that will be /usr/local/php-5.0.4), but for the sake of testing, you don't need to do that.

I quickly tested that my build worked by running:

    ./sapi/cli/php -m

and I saw:

    [PHP Modules]
    [Zend Modules]

And a really quick test to make sure that it doesn't blow up straight-away:

    ./sapi/cli/php -r '$d = new PDO("sqlite::memory:"); debug_zval_dump($d);'


    object(PDO)#1 (0) refcount(2){


It took a long time to compose this post, mostly due to the processor speed on that box; please put the info to good use!

I'm not an OSX expert, so I can't tell you how to set up your build environment (because I don't remember!), and it's not convenient for me to check things out. If you have OSX specific problems please ask around on the mailing list. If you run into a crash, use gdb to generate a backtrace and report the bug using the PECL bug tracker.

Good luck!

View Comments