I am currently trying to use PEAR to connect to a remote ORACLE. I tried with the normal PHP method and is works great
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("user", "password","//host/database");
$stmt = OCIParse($conn,"select * from PRODUCT");
OCIExecute($stmt);
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>Name</TH>";
print "<TH>Type</TH>";
print "<TH>Length</TH>";
print "</TR>";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_type = OCIColumnType($stmt,$i);
$column_size = OCIColumnSize($stmt,$i);
print "<TR>";
print "<TD>$column_name</TD>";
print "<TD>$column_type</TD>";
print "<TD>$column_size</TD>";
print "</TR>";
}
print "</TABLE>\n";
OCIFreeStatement($stmt);
OCILogoff($conn);
print "</PRE>";
print "</HTML>\n";
?>
So i tried it with PEAR method
<?
include_once('DB.php');
define("NR_DB_CONNECTION",'oci8://user:password@host/database');
// Create connection
$dbh = DB::connect(NR_DB_CONNECTION);
if (DB::isError($dbh)) {
print "Database connection failed: ";
print $dbh->getMessage();
exit;
}
$dbh->setErrorHandling(PEAR_ERROR_DIE);
// prepare statment
$stmt = "SELECT * from PRODUCT";
$result=$dbh->query($stmt);
$mode = DB_FETCHMODE_ASSOC;
while ($row = $result->fetchRow($mode)){
print "<pre>";
print_r($row);
print "</pre>";
}
// Database disconnect
$result->free();
$dbh->disconnect();
?>
The above code was having problem connecting to ORACLE, so what i did was to test wether the PEAR was installed properly. I did a test connection to my local MYSQL db
<?php
require_once 'DB.php';
$db_host = 'localhost';
$db_user = 'user';
$db_pass = 'password';
$db_name = 'database';
$dsn = "mysql://$db_user:$db_pass@$db_host/$db_name";
$conn =& DB::connect ($dsn);
if (DB::isError ($conn))
die ("Cannot connect: " . $conn->getMessage () . "\n");
$stmt = "SELECT * from PRODUCT";
$result =& $conn->query ($stmt);
if (DB::isError ($result))
die ("SELECT TABLE FAILED: " . $result->getMessage () . "\n");
while ($row =& $result->fetchRow (DB_FETCHMODE_ASSOC))
printf ("%s, %s<br>", $row["RegionID"], $row["Name"]);
?>
The above code was working great.
Tested with the normal OCIlogon, remote connect to ORACLE -> works fine
Tested with PEAR connecting to local MYSQL -> works fine
Tested with PEAR connecting to remote ORACLE -> not working...
Can someone shed some light on this?..have been bugging me for the pass 3 days..
THANKS...