Friday, November 16, 2007

PHP and Pear MDB2 Installation

Installation of Pear MDB2 (2.4.1) with Apache-2.2.6 PHP-5.2.3(with MySQL and MySQLI)

Backed up Existing PHP
[root@hareesh ~]# mv /usr/local/lib/php /usr/local/lib/php.bak
[root@hareesh ~]# mv /usr/local/bin/php /usr/local/bin/php.bak
[root@hareesh ~]# mv /usr/local/include/php /usr/local/include/php.bak

Installed PHP-5.2.3 with MySQL and MySQLI Support
[root@hareesh lib]# cd /usr/local/src/
[root@hareesh src]# tar xjf php-5.2.3.tar.bz2
[root@hareesh src]# cd php-5.2.3

[root@hareesh php-5.2.3]# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib --with-pear --with-mysql --with-mysql-sock=/tmp/mysql.sock --with-mysqli --with-mysqli-sock=/tmp/mysql.sock

[root@hareesh php-5.2.3]# make

Stopped Apache
[root@hareesh ~]# /usr/local/apache2/bin/apachectl stop
httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.46 for ServerName

Then Installed PHP
[root@hareesh php-5.2.3]# make install

[root@hareesh php-5.2.3]# /usr/local/apache2/bin/apachectl start
[root@hareesh php-5.2.3]# opera localhost/phpinfo.php

It works



MySQL Connectivity
mysql_native_php.php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>


[root@hareesh php-5.2.3]# opera localhost/mysql_native_php.php

Success


MySQLi Connectivity
mysqli_native_php.php
$mysqli = new mysqli("localhost", "root", "", "mysql");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", $mysqli->host_info);

/* close connection */
$mysqli->close();
?>


[root@hareesh php-5.2.3]# opera localhost/mysqli_native_php.php

Success
Pear MDB2 Installation


Reference

[root@hareesh PEAR_MDB]# pear install MDB2
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
downloading MDB2-2.4.1.tgz ...
Starting to download MDB2-2.4.1.tgz (119,790 bytes)
..........................done: 119,790 bytes
install ok: channel://pear.php.net/MDB2-2.4.1
MDB2: Optional feature fbsql available (Frontbase SQL driver for MDB2)
MDB2: Optional feature ibase available (Interbase/Firebird driver for MDB2)
MDB2: Optional feature mysql available (MySQL driver for MDB2)
MDB2: Optional feature mysqli available (MySQLi driver for MDB2)
MDB2: Optional feature mssql available (MS SQL Server driver for MDB2)
MDB2: Optional feature oci8 available (Oracle driver for MDB2)
MDB2: Optional feature pgsql available (PostgreSQL driver for MDB2)
MDB2: Optional feature querysim available (Querysim driver for MDB2)
MDB2: Optional feature sqlite available (SQLite2 driver for MDB2)
To install use "pear install pear/MDB2#featurename"

Installed PEAR-MDB2-mysql
[root@hareesh PEAR_MDB]# pear install MDB2#mysql
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
Skipping package "pear/MDB2", already installed as version 2.4.1
downloading MDB2_Driver_mysql-1.4.1.tgz ...
Starting to download MDB2_Driver_mysql-1.4.1.tgz (36,481 bytes)
..........done: 36,481 bytes
install ok: channel://pear.php.net/MDB2_Driver_mysql-1.4.1
[root@hareesh PEAR_MDB]#


Installed PEAR-MDB2-mysqli
[root@hareesh PEAR_MDB]# pear install MDB2#mysqli
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
Skipping package "pear/MDB2", already installed as version 2.4.1
downloading MDB2_Driver_mysqli-1.4.1.tgz ...
Starting to download MDB2_Driver_mysqli-1.4.1.tgz (38,064 bytes)
..........done: 38,064 bytes
install ok: channel://pear.php.net/MDB2_Driver_mysqli-1.4.1

MySQL Connectivity with MDB2
MDB2_mysql.php
// Create a valid MDB2 object named $mdb2
// at the beginning of your program...
require_once 'PEAR/MDB2.php';

$mdb2 =& MDB2::connect('mysql://root@localhost/myDB');
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}
// Proceed with getting some data...
$res =& $mdb2->query('SELECT * FROM a');
// Get each row of data on each iteration until
// there are no more rows
while (($row = $res->fetchRow())) {
// Assuming MDB2's default fetchmode is MDB2_FETCHMODE_ORDERED
echo $row[0] . "\n";
}
// while (($one = $res->fetchOne())) {
// echo $one . "\n";
// }
?>


[root@hareesh php-5.2.3]# opera localhost/MDB2_mysql.php

Success

MySQLi Connectivity with MDB2
MDB2_mysqli.php
// Create a valid MDB2 object named $mdb2
// at the beginning of your program...
require_once 'PEAR/MDB2.php';

$mdb2 =& MDB2::connect('mysqli://root@localhost/myDB');
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}

// Proceed with getting some data...
$res =& $mdb2->query('SELECT * FROM a');

// Get each row of data on each iteration until
// there are no more rows
while (($row = $res->fetchRow())) {
// Assuming MDB2's default fetchmode is MDB2_FETCHMODE_ORDERED
echo $row[0] . "\n";
}

// while (($one = $res->fetchOne())) {
// echo $one . "\n";
// }
?>

[root@hareesh php-5.2.3]# opera localhost/MDB2_mysqli.php

Success

Result
Working fine

Note : AFAIK MDB2 have no ODBC Driver
Reference

No comments: