PECL PDO Mysql

Introduction to PECL PDO_MySQL
PDO_MYSQL provides a mysql driver for PDO. Some PHP applications require this, so it can be useful to enable on a custom PHP 5 installation.

Note that since PHP 5.1, PDO is part of the PHP core and does not need to be installed. Instead, ensure you compile PHP using the option flag --with-pdo-mysql during config if using the Dreamhost MySQL servers.

Installing PECL PDO_MSYQL
Please Note: The installation of PECL pdo_mysql requires Installing_PHP5.

The default dreamhost PHP installation already has pdo_mysql, this is only for custom installations.

Below is the install script for the PECL pdo_mysql PHP module.

Please make sure to run 'dos2unix pdo_mysql.sh' from the shell if you used a Windows-based editor to create this file.

pdo_mysql.sh
set -e
 * 1) !/bin/sh


 * 1) Based off of the PECL Zip install script.

SRCDIR=${HOME}/source DISTDIR=${HOME}/dist DISTDEL="No" INSTALLDIR=${HOME}/php5 NICE=19
 * 1) User Configuration Options
 * 2) Temporary source directory
 * 1) Download temporary DIST files to which directory?
 * 1) Delete contents of DISTDIR after installation? (Default: Yes)
 * 1) Install to which directory?
 * 2) Note: This *MUST* be set to your PHP5 installation directory!
 * 1) Nice Level for Processes. (Depreciated)
 * 2) Higher is nicer, lower is less nice and could get your install process killed!

AUTOCONF="autoconf-2.61" AUTOMAKE="automake-1.10" PDOFEATURES="--prefix=${INSTALLDIR}"
 * 1) Program Version Configuration
 * 2) Don't touch unless you know what you're doing!
 * 1) What features do you want enabled?

set -e


 * 1) END User Configuration Options

sleep 1s
 * 1) DO NOT MODIFY BELOW ##########

export PATH=${INSTALLDIR}/bin:$PATH
 * 1) Push the install dir's bin directory into the path

if [ -d ${SRCDIR} ]; then echo "Source directory already exists! Cleaning it..." rm -rf $SRCDIR/* else echo "Creating source directory..." mkdir -p ${SRCDIR} fi if [ -d ${DISTDIR} ]; then echo ""; echo "Distribution directory already exists!"; echo "Clean it?" if [ ${DISTDEL} == "Yes" ] then echo ""; echo "Yes!"; echo "Cleaning now..."; echo "" rm -rf $DISTDIR/* else echo ""; echo "No!"; echo "Leaving the distribution directory intact."; echo "" fi else echo "Creating distribution directory..." mkdir -p ${DISTDIR} fi if [ -d ${INSTALLDIR}/lib/php/extensions ]; then echo "lib/php/extensions folder already exists! Doing nothing..." else mkdir -p ${INSTALLDIR}/lib/php/extensions fi
 * 1) Clear and/or create the source directory.
 * 1) Create the dist files directory if it doesn't exist
 * 2) optionally cleaning it if it does exist already.
 * 1) Make sure the extensions directory exists.

cores=2  # the number of cores/procs to use when building if [ $cores -a $cores -gt 1 ]; then j="-j$cores " fi OS=`uname -s` if [ "Darwin" = $OS ]; then sed=gnused makefile=makefile.macosx else makefile=makefile.linux_x86_ppc_alpha sed=sed fi
 * 1) Detect how many processors the system has (for more optimal compliation).

for i in $sed wget; do		 $i --version >/dev/null 2>&1 done

cd ${DISTDIR} set +e WGETOPT="-t1 -T10 -w5 -q -c"
 * 1) Check if packages already exist and get packages the ones that don't.
 * 1) Do not abort on errors.
 * 1) Wget options

if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then echo "Skipping wget of ${AUTOCONF}.tar.gz" else wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOCONF}.tar.gz # If primary mirror fails, use the alternative mirror. if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then echo "Got ${AUTOCONF}.tar.gz" else wget $WGETOPT ftp://ftp.gnu.org/gnu/autoconf/${AUTOCONF}.tar.gz # Check to make sure the alternative mirror worked. if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then echo "Got ${AUTOCONF}.tar.gz" else echo "Failed to get ${AUTOCONF}.tar.gz. Aborting install!" exit 0 fi fi fi if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then echo Skipping wget of ${AUTOMAKE}.tar.bz2 else wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOMAKE}.tar.bz2 # If primary mirror fails, use the alternative mirror. if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then echo "Got ${AUTOMAKE}.tar.bz2" else wget $WGETOPT ftp://ftp.gnu.org/gnu/automake/${AUTOMAKE}.tar.bz2 # Check to make sure the alternative mirror worked. if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then echo "Got ${AUTOMAKE}.tar.bz2" else echo "Failed to get ${AUTOMAKE}.tar.bz2. Aborting install!" exit 0 fi fi fi
 * 1) Do some of our own error checking here too.

set -e

cd ${SRCDIR} echo "Extracting ${AUTOCONF}..." tar xzf ${DISTDIR}/${AUTOCONF}.tar.gz > /dev/null echo "Done." echo "Extracting ${AUTOMAKE}..." tar xjf ${DISTDIR}/${AUTOMAKE}.tar.bz2 > /dev/null echo "Done."
 * 1) Extract the source files into the source directory.

cd ${SRCDIR}/${AUTOCONF} ./configure --prefix=${SRCDIR} nice -n ${NICE} make make install
 * 1) Compile deps and install Pecl pdo_mysql
 * 2) AUTOCONF
 * 1) make clean

cd ${SRCDIR}/${AUTOMAKE} ./configure --prefix=${SRCDIR} nice -n ${NICE} make make install
 * 1) AUTOMAKE
 * 1) make clean

cd ${HOME}

echo "Downloading PDO_MYSQL..." pecl download pdo_mysql echo "Done." echo "Extracting PDO_MYSQL..." pecl bundle pdo_mysql echo "Done"

export PATH=${SRCDIR}/bin:$PATH export PHP_PREFIX=${INSTALLDIR}/bin
 * 1) Required exports

echo "Building PDO_MYSQL...."

cd ${HOME}/PDO_MYSQL $PHP_PREFIX/phpize ./configure ${PDOFEATURES} nice -n ${NICE} make
 * 1) make clean

echo "Done!"

cp modules/pdo_mysql.so ${INSTALLDIR}/lib/php/extensions/pdo_mysql.so cp modules/pdo_mysql.la ${INSTALLDIR}/lib/php/extensions/pdo_mysql.la
 * 1) Copy the SO files

sleep 2s cd ${HOME} && clear
 * 1) Post install clean-up.

if [ ${DISTDEL} == "Yes" ]; then rm -rf $DISTDIR elif [ ${DISTDEL} == "No" ]; then echo "Your DISTDIR will not be cleaned." else echo "Unknown DISTDEL option! Cleaning your DISTDIR by default." fi
 * 1) rm -rf $SRCDIR

echo "Installation completed!" `date +%r`
 * 1) End of Install

64-bit caveats
If you are installing to a 64-bit system, then you may get an error from the PDO command line about running out of memory similar to the following: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 23040 bytes) in /usr/local/lib/php/PEAR/PackageFile/v2/Validator.php The root cause is that the command line PEAR PHP interpreter uses a different .ini file. The solution is to edit the following file (note: this requires root access) sudo vi /usr/local/lib/php/pearcmd.php Add the following line at about line 40 or so, where there are a few lines setting ini variables in a similar manner: @ini_set('memory_limit', '64M');

php.ini Modifications
Locate the following line(s) in your php.ini file: extension_dir = "./" Modify the extension_dir line to look like this, replacing username with the username of your account: extension_dir = "/home/username/php5/lib/php/extensions"
 * Directory in which the loadable extensions (modules) reside.
 * Directory in which the loadable extensions (modules) reside.

Now add the following near the very end of your current php.ini file.

[pdo_mysql] extension="pdo_mysql.so"