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 https://github.com/famsf/pecl-pdo-4d.git pdo_4d cd pdo_4d # Prepare the PHP extension for compiling phpize # Workaround acinclude.m4 pointing to incorrect header location. # See: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1393640 sudo ln -s /usr/include/php5/ /usr/include/php # Configure the package to the system ./configure --with-pdo-4d # Compile! make # 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 extension=pdo_4d.so > /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 extension=pdo_4d.so > /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 (http://www.4d.com), and Alter Way (http://www.alterway.fr) 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: https://github.com/famsf/4d-mysqldump
- Update 11/18/14: New simpler compilation procedure.
(Statically copied from previous site)
A.Y. Siu replied on November 4, 2013 - 9:22am
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.
brad replied on November 4, 2013 - 10:35am
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?
A.Y. Siu replied on November 4, 2013 - 11:09am
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!
brad replied on November 4, 2013 - 11:15am
Ha! You are welcome. Honestly, you caught me on a good day. ;)
A.Y. Siu replied on April 2, 2014 - 1:17pm
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.
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.
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).
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’].
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.
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.
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.
brad replied on May 8, 2014 - 5:08pm
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.
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.
Yes, that sort of complication is why I do everything with the data in MySQL. Haha!
The inconsistent capitalization lead me to strtolower everything in the 4d-mysqldump script: https://github.com/famsf/4d-mysqldump/blob/master/FourDDump.php#L163
Backwards Booleans! Argh. I flip them during export in 4d-mysqldump: https://github.com/famsf/4d-mysqldump/blob/master/FourDDump.php#L434
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!
A.Y. Siu replied on May 9, 2014 - 5:49am
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”
brad replied on November 18, 2014 - 1:56pm
You’ve run into: https://bugs.php.net/bug.php?id=65356 which is caused by missing PHP 5.5 support.
I’ve implemented all required fixes in a copy of the pdo_4d repo here: https://github.com/famsf/pecl-pdo-4d
B Thrasher replied on September 26, 2014 - 10:01am
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/pdo_4d.so’ - /usr/lib64/php/modules/pdo_4d.so: 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
brad replied on September 29, 2014 - 2:13pm
Seems like somehow your PHP ins’t compiled with the mbstring extension. It’s supposed to be included in 12.04: https://serverfault.com/questions/455388/how-to-install-php-xml-and-php-mbstring-on-php-5-4-9-4
B Thrasher replied on September 29, 2014 - 2:27pm
Yes, I finally figured out that I needed to install the mbstring module. Sorry for the intrusion! Everything is running great now.
Xer replied on October 14, 2015 - 8:02am
Thank you ;)
Jason Johnson replied on February 10, 2016 - 5:37pm
Brad - Thanks for this great post a coworker and I have patched the memory leaks and also the record / column limits in pdo_4d (the issues are really in lib4dsql). We have been using this in production for some time on a 135gb 4D database with several tables 100+ million rows.
brad replied on February 12, 2016 - 12:43am
I’m so sorry you have to use 4D that much! :) Great to hear you have the extension working better!
I don’t have access to merge PRs on the famsf repo anymore or even a 4D database to test against, but I can get your changes merged by a famsf employee. Your commits need to be rebased into a few organized PRs so the changes can someday be applied to the official php.net repos. This PR: https://github.com/famsf/pecl-pdo-4d/pull/3 needs to be updated to remove the extra commits.
Sylvain replied on September 7, 2016 - 12:59pm
I used 4d-mysqldump for year(s), and the migration to php 5.5 has been more than easy following these instructions. Thank you !
ikiK replied on January 18, 2017 - 6:11am
You Sir have saved me. Thank you for this post. I have tried to compile newer versions of this pdo with 6 different methods and os’s in last few weeks. I ended up installing ubuntu and follow your instructions. Now my script finally works like it should. It connects to 32 databases and works like a charm. Thank you.
Felipe Blanco replied on March 21, 2017 - 10:17am
I am getting this error:
configure: error: Cannot find php_pdo_driver.h.
I have php 5.6.
Thanks for your help
Gillouz replied on July 8, 2017 - 12:11pm
Thank you for the help, I used this driver for some year now and I get stuck with PHP7 fetchAll does not work… Any idea?