Skip to main content

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

Comments

Popular posts from this blog

Check remote UDP connectivity from Linux

Hi there, You all know how to check TCP port connectivity from a Linux or UNIX machine to a remote machine using telnet as per th example below $ telnet 127.0.0.1 25 but we can't adopt TELNET to check UDP connectivity. Linux and most of the UNIXes come with a network layer utility called nc (abbreviation for netcat) which is very useful to check UDP connectivity and to explore a lot with both TCP and UDP. An example is shown below # nc -v -u -z -w 3 172.24.16.131 123 Connection to 172.24.16.131 123 port [udp/ntp] succeeded!

The best putty package available

Bored of Black screened Task bar filling putty? Issues with porting Saved sessions from machine to machine? Do you like tabbed SSH sessions? Start using portaputty instead of normal putty and link it with puttycm . Puttycm supports sessions to be saved in its own Database files. You can use the Putty sessions you have saved already right inside putty. You can have any number of databases which allow you to arrange Remote servers in folders and convenient namings. I personally recommend creating Database with puttycm rather than using the sessions saved in putty which doesn't offer any option to create folders and saving sessions under that directory tree. You can even save username/password to get it logged automatically and there is an option to pass commands to be run soon after login. I can't recommend this since some bug was found with these options. Portaputty is a variant of putty which stores all the Configuration data in text files instead of MS Window

PING.sh

#!/usr/bin/env bash ## Ping all machines in a Network PING="$(which ping) -c 1 -W 1" echo "Enter Subnet(eg:192.168.0)" read Subnet echo "Do you want to PING the entire network or a RANGE of IPs ? Enter your choice" echo 1. Ping Entire Network echo 2. Ping a RANGE read choice if [ $choice = 1 ]; then { echo Pinging..... for((i=1;i<255;i++)); do ${PING} ${Subnet}.${i} > /dev/null 2> /dev/null if [ $? -eq 0 ]; then echo -e "${Subnet}.${i} is up" fi done } fi if [ $choice = 2 ]; then { echo Enter the Starting IP of Range read a echo Enter the Last IP of Range read b echo Pinging..... for((i=$a;i<$b;i++)); do ${PING} ${Subnet}.${i} > /dev/null 2> /dev/null if [ $? -eq 0 ]; then echo -e "${Subnet}.${i} is up" fi done } fi exit 0