Re: oracle 10g and pear

  • From: Mladen Gogala <gogala@xxxxxxxxxxxxx>
  • To: s.saravalli@xxxxxxxxx
  • Date: Wed, 12 Apr 2006 19:15:39 -0400

On 04/12/2006 11:25:50 AM, Simone Saravalli wrote:
> hi to everybody,
>    I use Oracle 10g Express and I'm dealing with the connection to the
> database in php through the use of pear. In order to connect to the
> database I use the function DB::connect() provided by the pear
> package, but google told me that the connection is allowed only up to
> oracle version 9. With the oci_connect() function always goes right,
> so I suspect there's something wrong in pear. Someone else has the
> same experience?
> 
> Thanks in advance, Simone Saravalli

PEAR::DB is a little bit outdated and a little bit slow, but other then that,
there is nothing wrong with it. It can connect to Oracle 10G, both R1 & R2 
because
it uses the underlying OCI8 driver, which can connect to Oracle 10g. The only
quirk is that with 10.2, the protection of some directories ($ORACLE_HOME/lib,
$ORACLE_HOME/network/admin, $ORACLE_HOME/nls) are wrong and needs to be fixed.
Fortunately, the latest patchset contains script 
$ORACLE_HOME/install/changePerm.sh
which will fix the protection bits. My advice nevertheless is to use ADOdb 
instead.
It is faster, it supports exceptions, it is extremely convenient and it is well
maintained, with newer releases appearing much more frequently then with 
PEAR::DB.
ADOdb can be found at http://adodb.sourceforge.net


Here is a little PHP script used for testing:
#!/usr/local/bin/php

<?php 
require_once('DB.php');
$DSN="oci8://scott:tiger@local";
$db=DB::connect($DSN);
if (DB::iserror($db)) {
   die($db->getUserInfo());
}
$db->autoCommit(FALSE);
$sql="select * from dept";
$sth=$db->query($sql);
if (DB::iserror($sth)) {
   die($sth->getUserInfo());
}
$cols=$db->tableInfo($sth);
echo "This result has ",count($cols)," columns\n";

foreach ($cols as &$col) {
    echo $col['name'],"\t";
}
echo "\n";
while ($sth->fetchinto($row)) {
      foreach ($row as &$val) {
              print "$val\t";
      }
      echo "\n";
}      
$tst=$db->prepare("delete from non_existing_table");
if (DB::isError($tst)) {
   die($tst->getDebugInfo());
}
print "Kilroy was here!\n";
$tst1=$db->execute($tst);
if (DB::isError($tst1)) {
   die($tst1->getDebugInfo());
}

?>


The output of the script is:

$ ./simone.php

This result has 3 columns
DEPTNO  DNAME   LOC
10      ACCOUNTING      NEW YORK
20      RESEARCH        DALLAS
30      SALES   CHICAGO
40      OPERATIONS      BOSTON
Kilroy was here!
delete from non_existing_table [nativecode=ORA-00942: table or view does not 
exist]

The "Kilroy" part was inserted for me to see when will the latest PEAR perform
parse operation. As it turns out, it does deferred parse, bundled with the 
"execute",
as expected. This is what I have:

Installed packages, channel pear.php.net:
=========================================
Package         Version State
Archive_Tar     1.3.1   stable
Config          1.10.6  stable
Console_Getargs 1.3.1   stable
Console_Getopt  1.2     stable
DB              1.7.6   stable
Date            1.4.6   stable
HTML_Common     1.2.2   stable
HTML_Form       1.3.0   stable
HTML_Table      1.6.1   stable
Log             1.9.3   stable
PEAR            1.4.9   stable
PHP_Beautifier  0.1.8   beta
Var_Dump        1.0.3   stable
XML_Parser      1.2.7   stable
XML_RPC         1.4.7   stable
XML_Util        1.1.1   stable
$

-- 
Mladen Gogala
http://www.mgogala.com

--
//www.freelists.org/webpage/oracle-l


Other related posts: