Compiling the PDO_4D extension in recent versions of PHP5

Are you running Ubuntu 12.04 or 14.04 ? Are you working in PHP5? Do you need to access 4D database hosted on an external server? Have you discovered that PDO_4D won't compile when downloaded via PECL? Have I narrowed this to 0.001% of the world yet? Still with me? Well! That is exciting.

Here is how you can compile and install PDO_4D:

# Install dependencies (You may need more)
sudo apt-get install php5-dev
# Clone a working version of the code from the FAMSF repo
git clone pdo_4d
cd pdo_4d
# Prepare the PHP extension for compiling
# Workaround acinclude.m4 pointing to incorrect header location.
# See:
sudo ln -s /usr/include/php5/ /usr/include/php
# Configure the package to the system
./configure --with-pdo-4d
# Compile!
# Copy the extension to PHP's library
sudo make install
# Create php5 module configuration file for PHP 5.4/5.5
sudo sh -c "echo > /etc/php5/mods-available/pdo_4d.ini"
# Enable the module for PHP 5.4/5.5
sudo php5enmod pdo_4d
# Enable the module for PHP 5.3
sudo sh -c "echo > /etc/php5/conf.d/pdo_4d.ini"
# Restart apache
sudo apache2ctl restart
# Check for PDO_4D in the PHP CLI Information
php -i | grep 4D

The last command should return something along the lines of

PDO drivers => 4D, mysql
PDO Driver for 4D => enabled
Provided by  => 4D (, and Alter Way (
This program makes use of the 4D SQL protocol: <br />4D v11 and up, Copyright (c) 2009 4D<img src="?=PDO_4D_LOGO_ID" align="right" alt="4D logo" border="0">

Wasn't that fun!?

Update 7/12/13: If you need to export/dump a 4D database to a MySQL formatted SQL file, this will help:
Update 11/18/14: New simpler compilation procedure.


Thanks for posting this up. I'm part of that miniscule percentage that this would be useful for, so I appreciate you documenting all this. I am running into a bit of an issue, though, and I'm using Ubuntu 12.03. Everything worked up until the last few commands. The piping into mods-available gets me this error:

sh: 1: cannot create /etc/php5/mods-available/pdo_4d.ini: Directory nonexistent

and then for the next command, I get

sudo: php5enmod: command not found

Any ideas or leads on how to fix those would be greatly appreciated. Thanks so much.

Oh! Oops! Apparently I got confused after staring at this stuff for far too long. I've corrected the directions. php5enmod doesn't exist at all, I was mixing up php5.3 with php5.4. Haha! Let me know if you have any other issues. I'm happy to hear someone else is using this information. Thanks!

I've been using the 4d-mysqldump on my dev server and local machine for months without issue. Are you hoping to use it also?

Wow! What a response time! Thanks for your help. Yes, those new directions worked just fine. I'm now going to have to figure out my PDO connection string, and then see what I can do. This is very exciting, because the documentation for 4D is very lacking out there. I'll definitely have a look at 4d-mysqldump, too. Thanks again!

Ha! You are welcome. Honestly, you caught me on a good day. ;)

I just wanted to say that this has been immensely helpful, and I've learned a few things about PDO 4D along the way. You may know this stuff already, but it may be helpful for anyone else who stumbles upon this page.

1. These instructions work fine on Ubuntu Precise (12.04), but they do not work on the latest Ubuntu Saucy (13.10). That's fine, though, because Precise is LTS and will get support for 3 more years.

2. PDO 4D does not seem to support table joins on more than 100 records or so. The workarounds are not ideal (nested while loops or temporarily dumping to another database to make proper queries).

3. The PDO syntax is pretty standard to get stuff out, but I found the names to be capitalized when you retrieve things. For example, if the name of a field in 4D is FirstName and you plop selected results into an associative array called $row, then you end up with $row['FIRSTNAME'] instead of $row['FirstName'].

4. Booleans are tricky. First of all, I can't seem to query on them, no matter how I try to phrase the select statement ("casting" does not work, for example, and simply comparing to 0 or 1 does not either). I end up having to retrieve the field and then compare it to 0 or 1 afterwards... and then it's backward. If the result is 1, it means false. If the result is 0, it means true.

5. If you're querying on dates, you use a variable format of m/d/y (or MM/DD/YY), but then when you retrieve dates, they'll often show up with garbage after the date and timestamp. Could be an encoding issue. Not sure.

6. One-sided LIKE queries do not work. You can do both sides, of course, but then you end up with not necessarily the results you're looking for.

As an aside, I've found 4D ODBC on a WAMP server to be better for getting information out of 4D. If you use the latest 4D ODBC driver from the 4D website and install it on a Windows server, and then use odbc_exec, odbc_fetch_row, and odbc_result, you can do traditional joins and boolean casting.

Thanks for all of the details! I've been using the 4d-mysqldump on a production website now for a year. While it could use some work, it's been working flawlessly. I've managed to avoid the majority of complex SQL and use PDO_4D simply for dumping to MySQL.

1. What's different about 13.10 I wonder? I've compiled PDO_4D on 12.04 and 13.04, but haven't tried it on 13.10.

2. Yes, that sort of complication is why I do everything with the data in MySQL. Haha!

3. The inconsistent capitalization lead me to strtolower everything in the 4d-mysqldump script:

4. Backwards Booleans! Argh. I flip them during export in 4d-mysqldump:

5. I haven't noticed a specific issue with dates. They've been importing correctly in my 4D->MySQL->Drupal via Migrate process. I'll keep an eye out.

I'm not surprised 4D's latest ODBC driver works well, but my servers are all GNU/Linux. Thanks again!

The 4D dump tool is pretty cool, and I do have some Linux servers, but it's honestly easiest with WAMP to use the ODBC driver with PHP to get reports out of 4D in real time. PDO 4D is very interesting, though, so I really appreciate you putting this tutorial together.

Not something you have to solve, of course, but in case you're curious, the error for Ubuntu 13.10 and 14.04 happens when you get to the make stage, and it outputs /home/username/pdo_4d/pdo_4d.c:44:23 fatal error: php_logos.h: No such file or directory #include "php_logos.h"

You've run into: which is caused by missing PHP 5.5 support.

I've implemented all required fixes in a copy of the pdo_4d repo here:

Hello, Brad -

I'm hoping you or someone else can give me some clues on how to fix this error. I go through all the steps you list above, but then I get this:
$ php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/' - /usr/lib64/php/modules/ undefined symbol: php_mb_convert_encoding in Unknown on line 0
PHP 5.3.3 (cli) (built: Jul 15 2014 08:48:08)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Any ideas?

Seems like somehow your PHP ins't compiled with the mbstring extension. It's supposed to be included in 12.04:

Yes, I finally figured out that I needed to install the mbstring module. Sorry for the intrusion! Everything is running great now.

Add new comment