Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

share|improve this question

4 Answers 4

up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
    
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 0:40
1  
phpize will generate a configure script when you run it. –  duskwuff Aug 23 '09 at 1:21
    
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 0:34

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.

share|improve this answer
    
nope, see my comment in @porneL's answer. –  Jason S Aug 27 '09 at 2: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 2:14
    
I'll refer you to my other answer to another one of your questions :) serverfault.com/questions/58198/building-php-on-osx/59345#59345 Check out 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.