views:

2727

answers:

3

How can I get PDO to work on my mac (os x 10.5)? I'm using the built in php and php in Zend/Eclipse. Can't seem to find useful drivers for it at all.

+1  A: 

I'm not sure this will help with the PDO drivers specifically, but you might look into BitNami's MAPPStack.

I had a ton of trouble with Postgres, PHP, and Apache on my Mac, some of it having to do with 64- vs 32-bit versions of some or all of them. So far, the BitNami MAPPStack install is working nicely in general. Maybe it will help with your PDO issues as well.

Alan
+2  A: 

Take a look at this PECL package: PDO_PGSQL

I haven't tried it myself, but I've been interested in playing with Postgres as an alternative to MySQL. If I have a chance to try it soon, I'll throw my results up here in case it helps.

Wilco
+5  A: 

I had to install the PDO_PGSQL driver recently on Leopard, and I ran across a multitude of problems. In my search for answers, I stumbled across this question. Now I have it successfully installed, and so, even though this question is quite old, I hope that what I've found can help others (like myself) who will undoubtedly run into similar problems.

The first thing you'll need to do is install PEAR, if you haven't done so already, since it doesn't come installed on Leopard by default.

Once you do that, use the PECL installer to download the PDO_PGSQL package:

$ pecl download pdo_pgsql
$ tar xzf PDO_PGSQL-1.0.2.tgz

(Note: you may have to run pecl as the superuser, i.e. sudo pecl.)

After that, since the PECL installer can't install the extension directly, you'll need to build and install it yourself:

$ cd PDO_PGSQL-1.0.2
$ phpize
$ ./configure --with-pdo-pgsql=/path/to/your/PostgreSQL/installation
$ make && sudo make install

If all goes well, you should have a file called "pdo_pgsql.so" sitting in a directory that should look something like "/usr/lib/php/extensions/no-debug-non-zts-20060613/" (the PECL installation should have outputted the directory it installed the extension to).

To finalize the installation, you'll need to edit your php.ini file. Find the section labeled "Dynamic Extensions", and underneath the list of (probably commented out) extensions, add this line:

extension=pdo_pgsql.so

Now, assuming this is the first time you've installed PHP extensions, there are two additional steps you need to take in order to get this working. First, in php.ini, find the extension_dir directive (under "Paths and Directories"), and change it to the directory that the pdo_pgsql.so file was installed in. For example, my extension_dir directive looks like:

extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613"

The second step, if you're on a 64-bit Intel Mac, involves making Apache run in 32-bit mode. (If there's a better strategy, I'd like to know, but for now, this is the best I could find.) In order to do this, edit the property list file located at /System/Library/LaunchDaemons/org.apache.httpd.plist. Find these two lines:

<key>ProgramArguments</key>
<array>

Under them, add these three lines:

<string>arch</string>
<string>-arch</string>
<string>i386</string>

Now, just restart Apache, and PDO_PGSQL will be up and running.

htw