[HOWTO] Get PDO and PDO_MYSQL working in PHP 5.2.5

midas

Verified User
Joined
May 3, 2007
Messages
19
I've never tried with MySQL 4.1 so I can't say that it'll work or not. Why not upgrade MySQL?
Due to websites only build on mysql 4 im not able to upgrade to 5 on this particular server. Yes, i hate it :)
 

nealdxmhost

Verified User
Joined
Jan 1, 2009
Messages
234
Location
Los Angeles CA
This is what I am getting after following your instructions;
/usr/local/bin/pecl install pdo
downloading PDO-1.0.3.tgz ...
Starting to download PDO-1.0.3.tgz (52,613 bytes)
.............done: 52,613 bytes
12 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
building in /var/tmp/pear-build-root/PDO-1.0.3
running: /root/tmp/pear/temp/PDO/configure
checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
ERROR: `/root/tmp/pear/temp/PDO/configure' failed

============================================

What am I missing or doing wrong?

I just recently had to do this so I thought I might as well share. There are a few threads already with some info, but it's not entirely complete in my opinion.

Let's get started.

1) First off, issue this command to check your pear/pecl config:

Code:
pecl config-show
This will show you your config. Now if your /tmp is mounted noexec, skip the following and jump to step 2) now.

My /tmp is mounted noexec and instead of messing with it, I just changed the config to a local writable directory.

Your config-show should have:

Code:
PEAR Installer cache directory cache_dir        /tmp/pear/cache
PEAR Installer download        download_dir     /tmp/pear/cache
PEAR Installer temp directory  temp_dir         /tmp/pear/temp
Take note of the /tmp paths.

Type and execute:

Code:
pear config-set cache_dir /root/tmp/pear/cache
pear config-set download_dir /root/tmp/pear/cache
pear config-set temp_dir /root/tmp/pear/temp
Feel free to change the path to your own liking.

2) Now we will install pdo and pdo_mysql extensions.

Type and execute:

Code:
pecl install pdo
pecl install pdo_mysql
Now check your extensions directory to make sure they were installed. For my purposes they were in /usr/local/lib/php/extensions/no-debug-non-zts-20060613.

You should see pdo.so and pdo_mysql.so there.

3) Next you will need to re-compile PHP5. Before doing so, edit the configure file and add the following:

Code:
	--enable-pdo=shared \
	--with-pdo-mysql=shared \
	--with-sqlite=shared \
	--with-pdo-sqlite=shared \
Next recompile PHP with your method of choice.

4) Last step is to edit your /usr/local/lib/php.ini file.

Change your extension_dir to:

Code:
extension_dir = /usr/local/lib/php/extensions/no-debug-non-zts-20060613
Change this path if yours is different.

Scroll down and add the following extensions:

Code:
extension=pdo.so
extension=pdo_mysql.so
Exit and save your php.ini.

5) Restart httpd and open up a phpinfo.php file. You should now see pdo/pdo_mysql entries.

TROUBLESHOOTING

A) If you are receiving the following warning/error:

Code:
PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'pdo_mysql.so' in Unknown on line 0
Try restarting mysqld first.
 

mkniskanen

Verified User
Joined
Sep 17, 2008
Messages
79
Location
Lieksa, Finland
What about PDO and PHP 5.3

EDIT: Just found out that the problem probably only applies to the PHP executable /usr/local/bin/php whereas the Apache module _might_ work ok. This is weird, anyhow and the problem remains because some of my cron scripts will make use of PDO functions.

Any input from anybody who has succeeded in compiling and installing PDO?

I have successfully upgraded to PHP 5.3 but none of the tricks seems to work. The build script seems to finish, the end of the script outputs this:

Code:
Installing PDO headers:          /usr/local/include/php/ext/pdo/
Increasing memory limit to 32M...
PHP 5.3.2 Installed.
Rewriting all users httpd.conf files, please wait...
In debug mode
Debug set to level 10
root priv set: uid:0 gid:0 euid:0 egid:0
pidfile written
staring queue
done queue
Restarting apache.
Stopping httpd:                                            [  OK  ]
Starting httpd:
Then, we test the result:

Code:
bash-3.2# /usr/local/bin/php
PHP Warning:  PHP Startup: PDO: Unable to initialize module
Module compiled with module API=20060613
PHP    compiled with module API=20090626
These options need to match
 in Unknown on line 0
PHP Warning:  PHP Startup: pdo_mysql: Unable to initialize module
Module compiled with module API=20060613
PHP    compiled with module API=20090626
These options need to match
 in Unknown on line 0
PHP Warning:  PHP Startup: apc: Unable to initialize module
Module compiled with module API=20060613
PHP    compiled with module API=20090626
What is even more alarming is that manual compilation will not work, either. The PECL installation system assumes that one can run scripts from the /tmp directory. This kind of setup is a pretty unsafe and should be avoided (I have been attacked once from there and I learned my lesson). So If you have done your security homework normal pecl installation will fail. So you will have to compile the whole thing manually. And here we go!

Code:
/home/tmp/PDO-1.0.3/pdo_dbh.c: In function 'pdo_stmt_instantiate':
/home/tmp/PDO-1.0.3/pdo_dbh.c:410: error: 'zval' has no member named 'refcount'
/home/tmp/PDO-1.0.3/pdo_dbh.c:411: error: 'zval' has no member named 'is_ref'
/home/tmp/PDO-1.0.3/pdo_dbh.c: In function 'pdo_stmt_construct':
/home/tmp/PDO-1.0.3/pdo_dbh.c:435: error: 'zend_fcall_info' has no member named 'object_pp'
/home/tmp/PDO-1.0.3/pdo_dbh.c:458: error: 'zend_fcall_info_cache' has no member named 'object_pp'
/home/tmp/PDO-1.0.3/pdo_dbh.c: In function 'zim_PDO_setAttribute':
/home/tmp/PDO-1.0.3/pdo_dbh.c:752: error: 'zval' has no member named 'refcount'
/home/tmp/PDO-1.0.3/pdo_dbh.c: In function 'zim_PDO_getAttribute':
/home/tmp/PDO-1.0.3/pdo_dbh.c:818: error: 'zval' has no member named 'refcount'
/home/tmp/PDO-1.0.3/pdo_dbh.c: In function 'pdo_hash_methods':
/home/tmp/PDO-1.0.3/pdo_dbh.c:1122: warning: assignment discards qualifiers from pointer target type
/home/tmp/PDO-1.0.3/pdo_dbh.c:1126: warning: assignment discards qualifiers from pointer target type
make: *** [pdo_dbh.lo] Error 1
I am pretty puzzled at the moment. Anybody with a hint. And: NO, I will not mount /tmp with an executable flag.

Markku
 
Last edited:

gman88

New member
Joined
Feb 3, 2011
Messages
1
Thanks for this - worked on ver. 5.26

You saved my butt with this - it worked, for me, precisely as described. I simply followed the directions and it worked! I was installing Drupal 7, for a client, and it couldn't detect MySQL. Thanks a million.
:)
 

Chyr0n

New member
Joined
Jun 9, 2015
Messages
1
php mysqli and pdo

G'day,

Is there anyway to specify which version of the mysqli api for php5 to use? The target environment I am writing for is using the 5.1.73 Version, whilst my phpInfo() indicates I have 5.5.43.
Any ideas?
 
Top