BC remote Oracle DBA - Call (800) 766-1884  
Oracle Consulting Oracle Training Development

Remote DBA

Remote DBA Plans  

Remote DBA Service

Remote DBA RAC

Remote DBA Oracle Home
Remote DBA Oracle Training
Remote DBA SQL Tuning Consulting
Remote DBA Oracle Tuning Consulting
Remote DBA Data Warehouse Consulting
Remote DBA Oracle Project Management
Remote DBA Oracle Security Assessment
Remote DBA Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Links
Remote DBA Oracle Monitoring
Remote DBA Support Benefits
Remote DBA Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





Remote DBA services

Remote DBA Support

Remote DBA RAC

Remote DBA Reasons

Remote Oracle Tuning

Remote DBA Links

Oracle DBA Support

Oracle DBA Forum

Oracle Disaster

Oracle Training

Oracle Tuning

Oracle Training

 Remote DBA SQL Server

Remote MSSQL Consulting

Oracle DBA Hosting

Oracle License Negotiation








Connecting to Oracle

Oracle Tips by Burleson Consulting

ADOdb follows a similar pattern of DSN (Data Source Name) because it was modeled after the same original as PEAR. The original are, of course URL-like database names used by JDBC drivers.  The DSN syntax for Oracle is:


The “database” part in the expression above is the TNS descriptor of the database to which the connection is being established. The driver is “oci8”, same as in the case of PEAR DB.

When the DSN is defined, the new connection is established by the following sequence:


The reader should notice the inclusion of the file, adodb.inc.php.  This file defines the basic ADOdb classes and must be included if ADOdb is to be used.

The code on the previous page creates a connection to the SCOTT schema on the database called “LOCAL”. As with PEAR DB, DSN can be split into separate fields for the database type, username, password and database descriptor. 


The variable $database represents the TNS descriptor for the desired Oracle database.  For non-Oracle databases, the syntax is different and should be checked in the on-line manual.

In the PEAR DB section, connecting to an Oracle instance was explained in Example 20. The following example is Example 20 rewritten using ADOdb:

Example 25


try {
   $sql="select * from emp";

catch (Exception $e) {
   echo "Error code is:".$e->getCode()
echo "This result has ".$ncols." columns\n"; 
foreach (range(0,$ncols-1) as $ind) {
     echo $col->name."\t";
 echo "\n";

while ($row=$sth->FetchRow()) {
      foreach (range(0,$ncols-1) as $ind) {
              echo $row[$ind]."\t";
     }   echo "\n";

Notice the password for the user SCOTT was specified as “lion”, obviously incorrect.  When the example is executed, the following results:

$ ./example25.php
Error code is:1017
oci8 error: [1017: ORA-01017: invalid username/password; logon
] in EXECUTE("select * from emp")

ADOdb works with PHP5 and throws an exception when an error occurs. To initiate such behavior, the inclusion of the adodb-exceptions.inc.php file is needed, in addition to the adodb.inc.php file, as was done in the header. ADOdb also differs from PEAR DB philosophically, because ADOdb exceptions return the error code belonging to the underlying database, while PEAR DB returns its own error, portable across all supported databases.

Also notice the error was returned in the EXECUTE, not in the connect function. ADOdb was built for speed and attempts to pack as many operations together as possible. By actually trying to connect only before the execute, ADOdb can potentially save a trip across the network.  This can lead to errors being returned in unexpected places. That is exactly what makes exceptions such a good tool for exception handling.

The problematic password is replaced with the correct password and the following results:

The result is exactly the same as in Example 20.

Methods such as FieldCount()and FetchField() are explained in the next section. They do pretty much what they are expected to do. The only important function in Example 25 that was not explained before is the range function.  The range function is a very useful function that creates a range of numbers in a form of an array and is very useful in the foreach expressions. The following shows what the online manual says about the range function:


(PHP 3>= 3.0.8, PHP 4 , PHP 5)

range --  Create an array containing a range of elements


array range ( number low, number high [, number step])

range() returns an array of elements from low to high, inclusive. If low > high, the sequence will be from high to low.

New Parameter

The optional step parameter was added in 5.0.0. If a step value is given, it will be used as the increment between elements in the sequence. step should be given as a positive number. If not specified, step will default to 1.


The above book excerpt is from  "Easy Oracle PHP: Creating Dynamic Web Pages with Oracle Data". 

You can buy it direct from the publisher for 50%-off and get instant access to the code depot of Oracle tuning scripts:



Expert Remote DBA

BC is America's oldest and largest Remote DBA Oracle support provider.  Get real Remote DBA experts, call
BC Remote DBA today.



Remote DBA Service

Oracle Tuning Book


Advance SQL Tuning Book 

BC Oracle support

Oracle books by Rampant

Oracle monitoring software







BC Remote Oracle Support

Remote DBA

Remote DBA Services

Copyright © 1996 -  2013 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.

Hit Counter