2008年8月30日 星期六

PHP5: Buile PHP5 + POD in SuSE 1.01

Environment:
VMWare SuSE 1.01 image

Test Case:
Connecting to a DB2 database with PHP (PDO)

Build Env Steps:

1. Install Apache Web Server
2. Install PHP5

Install follow rpm list via rpm -ivh *

apache2-2.2.3-16.15
apache2-devel-2.2.3-16.15
apache2-doc-2.2.3-16.17.3
apache2-mod_php5-5.1.2-29.50
apache2-prefork-2.2.3-16.15
apache2-worker-2.2.3-16.15
php5-5.1.2-29.50
php5-devel-5.1.2-29.50
php5-odbc-5.1.2-29.50
php5-pdo-5.1.2-29.50
php5-pear-5.1.2-29.50
php5-zlib-5.1.2-29.50


3. Re-Configure PHP5

Download php-5.1.2.tar.tar from internet
tar xvf php-5.1.2.tar.tar

./configure --enable-cli --with-apxs2=/usr/sbin/apxs2 --with-zlib --with-pdo-odbc=ibm-db2,/home/instv8/sqllib

4. update PEAR

pear list
pear upgrade PEAR

5. Install ibm_db2 extension

export PHP_PDO_SHARED=1
pecl install ibm_db2

--with-pdo-odbc=ibm-db2,/home/instv8/sqllib

6. Install PDO_ODBC extension

export PHP_PDO_SHARED=1
pecl install PDO_ODBC

--with-pdo-odbc=ibm-db2


7. vi /etc/php5/conf.d/ibm_db2.ini

extension=pdo.so
extension=ibm_db2.so
extension=pdo_odbc.so
ibm_db2.instance_name=instv8

8. vi /etc/php5/conf.d/pdo.ini
; extension=pdo.so

9. restart apache server
cd /etc/init.d
apache2 restart

10. verify PHP/PDO setup
phpinfo.php

phpinfo();

pdoinfo.php

foreach(PDO::getAvailableDrivers() as $driver)
{
echo $driver.'
';
}


11. Test PDO/ibm_db2 driver

ibm_db2_conn.php

$database = 'SAMPLE';
$user = 'instv8';
$password = 'instv8';

$conn = db2_connect($database, $user, $password);

if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
}


pdo_conn.php

try {
$connection = new PDO("odbc:SAMPLE", "db2inst1", "ibmdb2", array(
PDO::ATTR_PERSISTENT => TRUE,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);
}
catch (Exception $e) {
echo($e->getMessage());
}



PHP Tutorials Examples Introduction to PHP PDO
PHP PDO 學習筆記
PDO Functions

沒有留言: