1 Reply Latest reply on Oct 31, 2005 11:02 AM by 463561

    Help with connecting to DB using PEAR

    448226
      I am try to get a basic PEAR connection to work, but the only output on the webpage is the print statement on the first line.

      Here is my pear script:

      <?php
      print("pearconnect.php - starting script");
      require_once '/usr/share/pear/DB.php';
      $user = 'scott';
      $pass = 'tiger';
      $host = 'emerson.clearbean.com';
      $db_name = 'orcl';
      $dsn = "oci8://$user:$pass@$host/$db_name";

      $db = DB::connect($dsn);
      if (DB::isError($db))
      {
      die("Can't connect: ".$db->getMessage());
      }
      else
      {
      echo "Connected - OK";
      }

      print ("pearconnect.php - ending script");
      ?>

      However, I am successful in connecting with oci8. Here is my oci8 logic:

      <?php
      if ($c=OCILogon("scott", "tiger", "orcl")) {
      echo "Successfully connected to Oracle.\n";
      OCILogoff($c);
      } else {
      $err = OCIError();
      echo "Oracle Connect Error " . $err[text];
      }
      echo "Connection test complete";
      ?>

      Here is my tnsnames.ora file for reference:

      # tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.1.0/db_1/network/admin/tnsnames.ora
      # Generated by Oracle configuration tools.

      ORCL =
      (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = emerson.clearbean.com)(PORT = 1521))
      (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl.clearbean.com)
      )
      )

      EXTPROC_CONNECTION_DATA =
      (DESCRIPTION =
      (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
      )
      (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
      )
      )

      Just as a FYI, I am using Zend Core for Oracle. I have set my php.ini to display all errors. Any help would be greatly appreciated. I am just getting started using PHP with Oracle. Is using database abstraction with Oracle common? If so, is there a preference towards PEAR, ADOdb or any others?

      Thx, Ira
        • 1. Re: Help with connecting to DB using PEAR
          463561
          Use this simple script :

          <?PHP

          require_once 'DB.php';
          $dsn = "oci8://scott:tiger@emerson.clearbean.com/orcl";
          $db = DB::connect($dsn, false); if (DB::isError($db)) {  die ($db->getMessage());}

          $result = $db->query("SELECT 1+1 AS MYRESULT");

          while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
          echo "$row->MYRESULT";
          }


          ?>