1

I'm running OS X 10.5; it looks like it came with Apache and PHP installed (minus some minor configurations which I turned on per this page; I've used Apache before so I know the basics of how httpd.conf works).

I've got a pre-existing script which uses PDO. I've got a MySQL database and can easily configure my script to access the database via PDO MySQL or PDO ODBC. The problem is, that even though I enabled the PDO MySQL and PDO ODBC extensions in php.ini, phpinfo() reports the only PDO drivers are sqlite2 and sqlite. I'm guessing the relevant extension .dll or .so files are not present? How do I get them?

note: I'm using the built-in install for PHP. (see apple's page on enabling php, which doesn't say anything about configure or adding additional .so files)

Jason S
  • 626
  • 1
  • 16
  • 28

4 Answers4

2

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

Jeff Ober
  • 136
  • 1
1

In OSX 10.7 and 10.8 the PDO drivers for MySQL are available by default. However, you may need to make other changes as explained in this post.

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
hiraash
  • 11
  • 2
0

You need to run configure with argument:

--with-pdo-mysql=/sw

/sw if you use Fink. If you don't, change this to path where your include/mysql.h and lib/libmysqlclient.la are (locate mysql.h will help).

If you just want to add PDO extension to existing installation, then download PHP source, go to ext/pdo directory, run:

phpize && ./configure && make && sudo make install

This will create and install appropriate .so file for you. Script will tell you where it put it. Sometimes it gets directory wrong, so ensure that it matches extension_dir in your php.ini.

Kornel
  • 1,105
  • 1
  • 11
  • 16
  • I don't get it... where do I get "configure" (I have php-config) and where do I run it? – Jason S Aug 23 '09 at 00:40
  • 1
    phpize will generate a configure script when you run it. –  Aug 23 '09 at 01:21
  • 1
    thanks but it complains "configure: error: Due to the way that loadable modules work on OSX/Darwin, you need to compile the PDO package statically into the PHP core." :-( I guess I have to start over and build php from scratch :-( – Jason S Aug 25 '09 at 00:34
0

If the pdo_sqlite extension is already working, you don't need to re-install the pdo extension itself -- just the pdo_mysql extension.

Download the source code for the same version of PHP as is built-in, and:

cd ext/pdo_mysql
phpize
./configure --with-pdo-mysql=shared
make
sudo make install

Should be that easy.

patcoll
  • 146
  • 2
  • nope, see my comment in @porneL's answer. – Jason S Aug 27 '09 at 02:11
  • oh wait, that was the PDO directory. If I do that under ext/pdo_mysql, I get this error: "checking for mysql_config... not found configure: error: Cannot find MySQL header files under " I love fragile builds. >:( – Jason S Aug 27 '09 at 02:14
  • I'll refer you to my other answer to another one of your questions :) http://serverfault.com/questions/58198/building-php-on-osx/59345#59345 Check out [buildphp](http://github.com/patcoll/buildphp). Add the version of PHP you need (5.2.X I'm assuming) into the `@versions` hash along with the md5 hash for the tgz, and only enable the `mysql` extension under `php_modules`, execute `rake` and I'll bet you get a successful compile with a solid `pdo_mysql.so` in the `src/php-5.2.X/modules` folder. Plug that in and enable it in php.ini and you'll be good to go. – patcoll Aug 27 '09 at 13:14