ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:oracle_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
userguide:oracle_tutorial [2015/08/30 18:02] mnewnhamuserguide:oracle_tutorial [2015/12/26 18:35] mnewnham
Line 2: Line 2:
 This needs fixing This needs fixing
 </WRAP> </WRAP>
 +<WRAP right box>
 +== Author Credit ==
 +(c) 2004-2014 John Lim
 +</WRAP>
 +====== ADOdb & Oracle ======
 +
 +===== Description ====
 Using ADOdb with PHP and Oracle: an advanced tutorial Using ADOdb with PHP and Oracle: an advanced tutorial
  
- +===== Introduction =====
-(c) 2004-2014 John Lim. All rights reserved. +
- +
-1. Introduction+
  
 Oracle is the most popular commercial database used with PHP. There are many ways of accessing Oracle databases in PHP. These include: Oracle is the most popular commercial database used with PHP. There are many ways of accessing Oracle databases in PHP. These include:
  
-The oracle extension +  * The oracle extension 
-The oci8 extension +  The oci8 extension 
-PEAR DB library +  PEAR DB library 
-ADOdb library+  ADOdb library 
 The wide range of choices is confusing to someone just starting with Oracle and PHP. I will briefly summarize the differences, and show you the advantages of using ADOdb. The wide range of choices is confusing to someone just starting with Oracle and PHP. I will briefly summarize the differences, and show you the advantages of using ADOdb.
  
 First we have the C extensions which provide low-level access to Oracle functionality. These C extensions are precompiled into PHP, or linked in dynamically when the web server starts up. Just in case you need it, here's a guide to installing Oracle and PHP on Linux. First we have the C extensions which provide low-level access to Oracle functionality. These C extensions are precompiled into PHP, or linked in dynamically when the web server starts up. Just in case you need it, here's a guide to installing Oracle and PHP on Linux.
  
-Oracle extension Designed for Oracle 7 or earlier. This is obsolete. +===== Oracle extension ===== 
-Oci8 extension Despite it's name, which implies it is only for Oracle 8i, this is the standard method for accessing databases running Oracle 8i, 9i or 10g (and later).+Designed for Oracle 7 or earlier. This is obsolete. 
 +===== Oci8 extension =====  
 + 
 +Despite it's name, which implies it is only for Oracle 8i, this is the standard method for accessing databases running Oracle 8i, 9i or 10g (and later). 
 Here is an example of using the oci8 extension to query the emp table of the scott schema with bind parameters: Here is an example of using the oci8 extension to query the emp table of the scott schema with bind parameters:
 +<code php>
  
 $conn = OCILogon("scott","tiger", $tnsName); $conn = OCILogon("scott","tiger", $tnsName);
Line 33: Line 43:
  echo "<hr>";  echo "<hr>";
 } }
 +</code>
 +
 This generates the following output: This generates the following output:
  
-Array ( [0] => 7902 [1] => FORD [2] => ANALYST [3] => 7566 [4] => 03/DEC/81 [5] => 3000 [7] => 20 ) +  Array ( [0] => 7902 [1] => FORD [2] => ANALYST [3] => 7566 [4] => 03/DEC/81 [5] => 3000 [7] => 20 ) 
-Array ( [0] => 7934 [1] => MILLER [2] => CLERK [3] => 7782 [4] => 23/JAN/82 [5] => 1300 [7] => 10 )+  Array ( [0] => 7934 [1] => MILLER [2] => CLERK [3] => 7782 [4] => 23/JAN/82 [5] => 1300 [7] => 10 ) 
 +  
 We also have many higher level PHP libraries that allow you to simplify the above code. The most popular are PEAR DB and ADOdb. Here are some of the differences between these libraries: We also have many higher level PHP libraries that allow you to simplify the above code. The most popular are PEAR DB and ADOdb. Here are some of the differences between these libraries:
  
-Feature PEAR DB 1.6 ADOdb 4.52 +^Feature^PEAR DB 1.6^ADOdb| 
-General Style Simple, easy to use. Lacks Oracle specific functionality. Has multi-tier design. Simple high-level design for beginners, and also lower-level advanced Oracle functionality. +|General Style|Simple, easy to use. Lacks Oracle specific functionality.|Has multi-tier design. Simple high-level design for beginners, and also lower-level advanced Oracle functionality.| 
-Support for Prepare Yes, but only on one statement, as the last prepare overwrites previous prepares. Yes (multiple simultaneous prepare's allowed) +|Support for Prepare|Yes, but only on one statement, as the last prepare overwrites previous prepares.|Yes (multiple simultaneous prepare's allowed)| 
-Support for LOBs No Yes, using update semantics +|Support for LOBs|No|Yes, using update semantics| 
-Support for REF Cursors No Yes +|Support for REF Cursors|No|Yes| 
-Support for IN Parameters Yes Yes +|Support for IN Parameters|Yes|Yes| 
-Support for OUT Parameters No Yes +|Support for OUT Parameters|No|Yes| 
-Schema creation using XML No Yes, including ability to define tablespaces and constraints +|Schema creation using XML|No|Yes, including ability to define tablespaces and constraints| 
-Provides database portability features No Yes, has some ability to abstract features that differ between databases such as dates, bind parameters, and data types. +|Provides database portability features|No|Yes, has some ability to abstract features that differ between databases such as dates, bind parameters, and data types.| 
-Performance monitoring and tracing No Yes. SQL can be traced and linked to web page it was executed on. Explain plan support included. +|Performance monitoring and tracing|No|Yes. SQL can be traced and linked to web page it was executed on. Explain plan support included.| 
-Recordset caching for frequently used queries No Yes. Provides great speedups for SQL involving complex where, group-by and order-by clauses. +|Recordset caching for frequently used queries|No|Yes. Provides great speedups for SQL involving complex where, group-by and order-by clauses.| 
-Popularity Yes, part of PEAR release Yes, many open source projects are using this software, including PostNuke, Xaraya, Mambo, Tiki Wiki. +|Speed|Medium speed.|Very high speed. Fastest database abstraction library available for PHP. Benchmarks are available.| 
-Speed Medium speed. Very high speed. Fastest database abstraction library available for PHP. Benchmarks are available. +|High Speed Extension available| No|Yes. You can install the optional ADOdb extension, which reimplements the most frequently used parts of ADOdb as fast C code. Note that the source code version of ADOdb runs just fine without this extension, and only makes use of the extension if detected.
-High Speed Extension available No Yes. You can install the optional ADOdb extension, which reimplements the most frequently used parts of ADOdb as fast C code. Note that the source code version of ADOdb runs just fine without this extension, and only makes use of the extension if detected.+
 PEAR DB is good enough for simple web apps. But if you need more power, you can see ADOdb offers more sophisticated functionality. The rest of this article will concentrate on using ADOdb with Oracle. You can find out more about connecting to Oracle later in this guide. PEAR DB is good enough for simple web apps. But if you need more power, you can see ADOdb offers more sophisticated functionality. The rest of this article will concentrate on using ADOdb with Oracle. You can find out more about connecting to Oracle later in this guide.
  
-ADOdb Example+===== ADOdb Example =====
  
 In ADOdb, the above oci8 example querying the emp table could be written as: In ADOdb, the above oci8 example querying the emp table could be written as:
  
 +<code php>
 include "/path/to/adodb.inc.php"; include "/path/to/adodb.inc.php";
 +
 $db = NewADOConnection("oci8"); $db = NewADOConnection("oci8");
 $db->Connect($tnsName, "scott", "tiger"); $db->Connect($tnsName, "scott", "tiger");
Line 65: Line 80:
 $rs = $db->Execute("select * from emp where empno>:emp order by empno", $rs = $db->Execute("select * from emp where empno>:emp order by empno",
                     array('emp' => 7900));                     array('emp' => 7900));
-while ($arr = $rs->FetchRow()) {+while ($arr = $rs->FetchRow()) 
 +{
     print_r($arr);     print_r($arr);
- echo "<hr>";+    echo "<hr>";
 } }
 +</code>
 +
 The Execute( ) function returns a recordset object, and you can retrieve the rows returned using $recordset->FetchRow( ). The Execute( ) function returns a recordset object, and you can retrieve the rows returned using $recordset->FetchRow( ).
  
 If we ignore the initial connection preamble, we can see the ADOdb version is much easier and simpler: If we ignore the initial connection preamble, we can see the ADOdb version is much easier and simpler:
  
 +<code php>
 Oci8 ADOdb Oci8 ADOdb
 $stmt = OCIParse($conn, $stmt = OCIParse($conn,
Line 91: Line 110:
  echo "<hr>";  echo "<hr>";
 } }
- +</code> 
  
-2. ADOdb Query Semantics+===== ADOdb Query Semantics =====
  
 You can also query the database using the standard Microsoft ADO MoveNext( ) metaphor. The data array for the current row is stored in the fields property of the recordset object, $rs. MoveNext( ) offers the highest performance among all the techniques for iterating through a recordset: You can also query the database using the standard Microsoft ADO MoveNext( ) metaphor. The data array for the current row is stored in the fields property of the recordset object, $rs. MoveNext( ) offers the highest performance among all the techniques for iterating through a recordset:
  
 +<code php>
 $rs = $db->Execute("select * from emp where empno>:emp", array('emp' => 7900)); $rs = $db->Execute("select * from emp where empno>:emp", array('emp' => 7900));
 while (!$rs->EOF) { while (!$rs->EOF) {
Line 102: Line 122:
  $rs->MoveNext();  $rs->MoveNext();
 } }
 +
 +</code>
 +
 And if you are interested in having the data returned in a 2-dimensional array, you can use: And if you are interested in having the data returned in a 2-dimensional array, you can use:
  
Line 117: Line 140:
 The $offset parameter is optional. The $offset parameter is optional.
  
-Array Fetch Mode+===== Prepare =====
  
-When data is being returned in an array, you can choose the type of array the data is returned in. +Using Prepare() For Frequently Used Statements
- +
-Numeric indexes - use $connection->SetFetchMode(ADODB_FETCH_NUM). +
-Associative indexes - the keys of the array are the names of the fields (in upper-case). Use $connection->SetFetchMode(ADODB_FETCH_ASSOC). +
-Both numeric and associative indexes - use $connection->SetFetchMode(ADODB_FETCH_BOTH). +
-The default is ADODB_FETCH_BOTH for Oracle. +
- +
-Caching +
- +
-You can define a database cache directory using $ADODB_CACHE_DIR, and cache the results of frequently used queries that rarely change. This is particularly useful for SQL with complex where clauses and group-by's and order-by's. It is also good for relieving heavily-loaded database servers. +
- +
-This example will cache the following select statement for 3600 seconds (1 hour): +
- +
-$ADODB_CACHE_DIR = '/var/adodb/tmp'; +
-$rs = $db->CacheExecute(3600, "select names from allcountries order by 1"); +
-There are analogous CacheGetArray( ), CacheGetRow( ), CacheGetOne( ) and CacheSelectLimit( ) functions. The first parameter is the number of seconds to cache. You can also pass a bind array as a 3rd parameter (not shown above). +
-There is an alternative syntax for the caching functions. The first parameter is omitted, and you set the cacheSecs property of the connection object: +
- +
-$ADODB_CACHE_DIR = '/var/adodb/tmp'; +
-$connection->cacheSecs = 3600; +
-$rs = $connection->CacheExecute($sql, array('id' => 1)); +
-  +
- +
-3. Using Prepare( ) For Frequently Used Statements+
  
 Prepare( ) is for compiling frequently used SQL statement for reuse. For example, suppose we have a large array which needs to be inserted into an Oracle database. The following will result in a massive speedup in query execution (at least 20-40%), as the SQL statement only needs to be compiled once: Prepare( ) is for compiling frequently used SQL statement for reuse. For example, suppose we have a large array which needs to be inserted into an Oracle database. The following will result in a massive speedup in query execution (at least 20-40%), as the SQL statement only needs to be compiled once:
  
 +<code php>
 $stmt = $db->Prepare('insert into table (field1, field2) values (:f1, :f2)'); $stmt = $db->Prepare('insert into table (field1, field2) values (:f1, :f2)');
 foreach ($arrayToInsert as $key => $value) { foreach ($arrayToInsert as $key => $value) {
  $db->Execute($stmt, array('f1' => $key, 'f2' => $val);  $db->Execute($stmt, array('f1' => $key, 'f2' => $val);
 } }
- +</code> 
  
-4. Working With LOBs+===== Working With LOBs =====
  
 Oracle treats data which is more than 4000 bytes in length specially. These are called Large Objects, or LOBs for short. Binary LOBs are BLOBs, and character LOBs are CLOBs. In most Oracle libraries, you need to do a lot of work to process LOBs, probably because Oracle designed it to work in systems with little memory. ADOdb tries to make things easy by assuming the LOB can fit into main memory. Oracle treats data which is more than 4000 bytes in length specially. These are called Large Objects, or LOBs for short. Binary LOBs are BLOBs, and character LOBs are CLOBs. In most Oracle libraries, you need to do a lot of work to process LOBs, probably because Oracle designed it to work in systems with little memory. ADOdb tries to make things easy by assuming the LOB can fit into main memory.
Line 160: Line 161:
 For updating records with LOBs, the functions UpdateBlob( ) and UpdateClob( ) are provided. Here's a BLOB example. The parameters should be self-explanatory: For updating records with LOBs, the functions UpdateBlob( ) and UpdateClob( ) are provided. Here's a BLOB example. The parameters should be self-explanatory:
  
 +<code php>
 $ok = $db->Execute("insert into aTable (id, name, ablob) $ok = $db->Execute("insert into aTable (id, name, ablob)
                                 values (aSequence.nextVal, 'Name', null)");                                 values (aSequence.nextVal, 'Name', null)");
Line 165: Line 167:
 # params: $tableName, $blobFieldName, $blobValue, $whereClause # params: $tableName, $blobFieldName, $blobValue, $whereClause
 $db->UpdateBlob('aTable', 'ablob', $blobValue, 'id=aSequence.currVal'); $db->UpdateBlob('aTable', 'ablob', $blobValue, 'id=aSequence.currVal');
 +</code>
 +
 and the analogous CLOB example: and the analogous CLOB example:
  
 +<code php>
 $ok = $db->Execute("insert into aTable (id, name, aclob) $ok = $db->Execute("insert into aTable (id, name, aclob)
                                 values (aSequence.nextVal, 'Name', null)");                                 values (aSequence.nextVal, 'Name', null)");
 if (!$ok) return LogError($db->ErrorMsg()); if (!$ok) return LogError($db->ErrorMsg());
 $db->UpdateClob('aTable', 'aclob', $clobValue, 'id=aSequence.currVal'); $db->UpdateClob('aTable', 'aclob', $clobValue, 'id=aSequence.currVal');
 +</code>
 Note that LogError( ) is a user-defined function, and not part of ADOdb. Note that LogError( ) is a user-defined function, and not part of ADOdb.
  
 Inserting LOBs is more complicated. Since ADOdb 4.55, we allow you to do this (assuming that the photo field is a BLOB, and we want to store $blob_data into this field, and the primary key is the id field): Inserting LOBs is more complicated. Since ADOdb 4.55, we allow you to do this (assuming that the photo field is a BLOB, and we want to store $blob_data into this field, and the primary key is the id field):
  
- $sql = "INSERT INTO photos ( ID, photo) ". +<code php> 
- "VALUES ( :id, empty_blob() )". +$sql = "INSERT INTO photos ( ID, photo) ". 
- " RETURNING photo INTO :xx";+ "VALUES ( :id, empty_blob() )". 
 + " RETURNING photo INTO :xx";
  
-  $stmt = $db->PrepareSP($sql); +$stmt = $db->PrepareSP($sql); 
- $db->InParameter($stmt, $id, 'id'); +$db->InParameter($stmt, $id, 'id'); 
- $blob = $db->InParameter($stmt, $blob_data, 'xx',-1, OCI_B_BLOB); +$blob = $db->InParameter($stmt, $blob_data, 'xx',-1, OCI_B_BLOB); 
- $db->StartTrans(); +$db->StartTrans(); 
- $ok = $db->Execute($stmt); +$ok = $db->Execute($stmt); 
- $db->CompleteTrans(); +$db->CompleteTrans(); 
-5. REF CURSORs+</code> 
 + 
 +===== REF CURSORs =====
  
 Oracle recordsets can be passed around as variables called REF Cursors. For example, in PL/SQL, we could define a function open_tab that returns a REF CURSOR in the first parameter: Oracle recordsets can be passed around as variables called REF Cursors. For example, in PL/SQL, we could define a function open_tab that returns a REF CURSOR in the first parameter:
  
-TYPE TabType IS REF CURSOR RETURN TAB%ROWTYPE; +  TYPE TabType IS REF CURSOR RETURN TAB%ROWTYPE; 
- +  PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames IN VARCHAR) IS 
-PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames IN VARCHAR) IS +  BEGIN 
- BEGIN +    OPEN tabcursor FOR SELECT * FROM TAB WHERE tname LIKE tablenames; 
- OPEN tabcursor FOR SELECT * FROM TAB WHERE tname LIKE tablenames; +  END open_tab; 
- END open_tab;+  
 In ADOdb, we could access this REF Cursor using the ExecuteCursor() function. The following will find all table names that begin with 'A' in the current schema: In ADOdb, we could access this REF Cursor using the ExecuteCursor() function. The following will find all table names that begin with 'A' in the current schema:
 +<code php>
 $rs = $db->ExecuteCursor("BEGIN open_tab(:refc,'A%'); END;",'refc'); $rs = $db->ExecuteCursor("BEGIN open_tab(:refc,'A%'); END;",'refc');
-while ($arr = $rs->FetchRow()) print_r($arr);+while ($arr = $rs->FetchRow())  
 +    print_r($arr); 
 +</code> 
 The first parameter is the PL/SQL statement, and the second parameter is the name of the REF Cursor. The first parameter is the PL/SQL statement, and the second parameter is the name of the REF Cursor.
  
    
- +===== In and Out Parameters =====
-6. In and Out Parameters+
  
 The following PL/SQL stored procedure requires an input variable, and returns a result into an output variable: The following PL/SQL stored procedure requires an input variable, and returns a result into an output variable:
  
-PROCEDURE data_out(input IN VARCHAR, output OUT VARCHAR) IS +  PROCEDURE data_out(input IN VARCHAR, output OUT VARCHAR) IS 
- BEGIN +  BEGIN 
- output := 'I love '||input; +    output := 'I love '||input; 
- END;+  END; 
 +  
 The following ADOdb code allows you to call the stored procedure: The following ADOdb code allows you to call the stored procedure:
 +<code php>
 $stmt = $db->PrepareSP("BEGIN adodb.data_out(:a1, :a2); END;"); $stmt = $db->PrepareSP("BEGIN adodb.data_out(:a1, :a2); END;");
 $input = 'Sophia Loren'; $input = 'Sophia Loren';
Line 219: Line 231:
 $ok = $db->Execute($stmt); $ok = $db->Execute($stmt);
 if ($ok) echo ($output == 'I love Sophia Loren') ? 'OK' : 'Failed'; if ($ok) echo ($output == 'I love Sophia Loren') ? 'OK' : 'Failed';
 +</code>
 +
 PrepareSP( ) is a special function that knows about bind parameters. The main limitation currently is that IN OUT parameters do not work. PrepareSP( ) is a special function that knows about bind parameters. The main limitation currently is that IN OUT parameters do not work.
  
Line 303: Line 317:
 oci8 The default high performance driver. The keys of associative arrays returned in a recordset are upper-case. oci8 The default high performance driver. The keys of associative arrays returned in a recordset are upper-case.
 oci8po The portable Oracle driver. Slightly slower than oci8. This driver uses ? instead of :bindvar for binding variables, which is the standard for other databases. Also the keys of associative arrays are in lower-case like other databases. oci8po The portable Oracle driver. Slightly slower than oci8. This driver uses ? instead of :bindvar for binding variables, which is the standard for other databases. Also the keys of associative arrays are in lower-case like other databases.
 +
 Here's an example of calling the oci8po driver. Note that the bind variables use question-mark: Here's an example of calling the oci8po driver. Note that the bind variables use question-mark:
  
 +<code php>
 $db = NewADOConnection('oci8po'); $db = NewADOConnection('oci8po');
 $db->Connect($tns, $user, $pwd); $db->Connect($tns, $user, $pwd);
 $db->Execute("insert into atable (f1, f2) values (?,?)", array(12, 'abc')); $db->Execute("insert into atable (f1, f2) values (?,?)", array(12, 'abc'));
- +</code>
  
-9. Connecting to Oracle+===== Connecting to Oracle =====
  
 Before you can use ADOdb, you need to have the Oracle client installed and setup the oci8 extension. This extension comes pre-compiled for Windows (but you still need to enable it in the php.ini file). For information on compiling the oci8 extension for PHP and Apache on Unix, there is an excellent guide at oracle.com. Before you can use ADOdb, you need to have the Oracle client installed and setup the oci8 extension. This extension comes pre-compiled for Windows (but you still need to enable it in the php.ini file). For information on compiling the oci8 extension for PHP and Apache on Unix, there is an excellent guide at oracle.com.
  
-Should You Use Persistent Connections+==== Should You Use Persistent Connections ====
  
 One question that is frequently asked is should you use persistent connections to Oracle. Persistent connections allow PHP to recycle existing connections, reusing them after the previous web pages have completed. Non-persistent connections close automatically after the web page has completed. Persistent connections are faster because the cost of reconnecting is expensive, but there is additional resource overhead. As an alternative, Oracle allows you to pool and reuse server processes; this is called Shared Server (also known as MTS). One question that is frequently asked is should you use persistent connections to Oracle. Persistent connections allow PHP to recycle existing connections, reusing them after the previous web pages have completed. Non-persistent connections close automatically after the web page has completed. Persistent connections are faster because the cost of reconnecting is expensive, but there is additional resource overhead. As an alternative, Oracle allows you to pool and reuse server processes; this is called Shared Server (also known as MTS).
Line 320: Line 336:
 The author's benchmarks suggest that using non-persistent connections and the Shared Server configuration offer the best performance. If Shared Server is not an option, only then consider using persistent connections. The author's benchmarks suggest that using non-persistent connections and the Shared Server configuration offer the best performance. If Shared Server is not an option, only then consider using persistent connections.
  
-Connection Examples+===== Connection Examples =====
  
 Just in case you are having problems connecting to Oracle, here are some examples: Just in case you are having problems connecting to Oracle, here are some examples:
Line 326: Line 342:
 a. PHP and Oracle reside on the same machine, use default SID, with non-persistent connections: a. PHP and Oracle reside on the same machine, use default SID, with non-persistent connections:
  
- $conn = NewADOConnection('oci8'); +  $conn = NewADOConnection('oci8'); 
- $conn->Connect(false, 'scott', 'tiger');+  $conn->Connect(false, 'scott', 'tiger');
 b. TNS Name defined in tnsnames.ora (or ONAMES or HOSTNAMES), eg. 'myTNS', using persistent connections: b. TNS Name defined in tnsnames.ora (or ONAMES or HOSTNAMES), eg. 'myTNS', using persistent connections:
  
- $conn = NewADOConnection('oci8'); +  $conn = NewADOConnection('oci8'); 
- $conn->PConnect(false, 'scott', 'tiger', 'myTNS');+  $conn->PConnect(false, 'scott', 'tiger', 'myTNS'); 
 or or
  
-  $conn->PConnect('myTNS', 'scott', 'tiger');+  $conn->PConnect('myTNS', 'scott', 'tiger'); 
 c. Host Address and SID c. Host Address and SID
  
- $conn->connectSID = true; +  $conn->connectSID = true; 
- $conn->Connect('192.168.0.1', 'scott', 'tiger', 'SID');+  $conn->Connect('192.168.0.1', 'scott', 'tiger', 'SID'); 
 d. Host Address and Service Name d. Host Address and Service Name
  
- $conn->Connect('192.168.0.1', 'scott', 'tiger', 'servicename');+  $conn->Connect('192.168.0.1', 'scott', 'tiger', 'servicename'); 
 e. Oracle connection string: e. Oracle connection string:
  
- $cstr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port)) +  $cstr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port))(CONNECT_DATA=(SID=$sid)))"; 
- (CONNECT_DATA=(SID=$sid)))"; +  $conn->Connect($cstr, 'scott', 'tiger'); 
- $conn->Connect($cstr, 'scott', 'tiger');+
 f. ADOdb data source names (dsn): f. ADOdb data source names (dsn):
  
- $dsn = 'oci8://user:pwd@tnsname/?persist';  # persist is optional +  $dsn = 'oci8://user:pwd@tnsname/?persist';  # persist is optional 
- $conn = ADONewConnection($dsn);  # no need for Connect/PConnect+  $conn = ADONewConnection($dsn);  # no need for Connect/PConnect
  
- $dsn = 'oci8://user:pwd@host/sid'; +  $dsn = 'oci8://user:pwd@host/sid'; 
- $conn = ADONewConnection($dsn);+  $conn = ADONewConnection($dsn); 
 + 
 +  $dsn = 'oci8://user:pwd@/';   # oracle on local machine 
 +  $conn = ADONewConnection($dsn);
  
- $dsn = 'oci8://user:pwd@/';   # oracle on local machine 
- $conn = ADONewConnection($dsn); 
 With ADOdb data source names, you don't have to call Connect( ) or PConnect( ). With ADOdb data source names, you don't have to call Connect( ) or PConnect( ).
  
-  
  
-10. Error Checking+===== Error Checking =====
  
 The examples in this article are easy to read but a bit simplistic because we ignore error-handling. Execute( ) and Connect( ) will return false on error. So a more realistic way to call Connect( ) and Execute( ) is: The examples in this article are easy to read but a bit simplistic because we ignore error-handling. Execute( ) and Connect( ) will return false on error. So a more realistic way to call Connect( ) and Execute( ) is:
  
 +<code php>
 function InvokeErrorHandler() function InvokeErrorHandler()
 { {
Line 379: Line 400:
  echo "<hr>";  echo "<hr>";
 } }
 +</code>
 +
 You can retrieve the error message and error number of the last SQL statement executed from ErrorMsg( ) and ErrorNo( ). You can also define a custom error handler function. ADOdb also supports throwing exceptions in PHP5. You can retrieve the error message and error number of the last SQL statement executed from ErrorMsg( ) and ErrorNo( ). You can also define a custom error handler function. ADOdb also supports throwing exceptions in PHP5.
  
    
  
-Handling Large Recordsets (added 27 May 2005)+===== Handling Large Recordsets =====
  
 The oci8 driver does not support counting the number of records returned in a SELECT statement, so the function RecordCount() is emulated when the global variable $ADODB_COUNTRECS is set to true, which is the default. We emulate this by buffering all the records. This can take up large amounts of memory for big recordsets. Set $ADODB_COUNTRECS to false for the best performance. The oci8 driver does not support counting the number of records returned in a SELECT statement, so the function RecordCount() is emulated when the global variable $ADODB_COUNTRECS is set to true, which is the default. We emulate this by buffering all the records. This can take up large amounts of memory for big recordsets. Set $ADODB_COUNTRECS to false for the best performance.
 This variable is checked every time a query is executed, so you can selectively choose which recordsets to count. This variable is checked every time a query is executed, so you can selectively choose which recordsets to count.
  
-  +===== Resources =====
- +
-11. Other ADOdb Features +
- +
-Schema generation. This allows you to define a schema using XML and import it into different RDBMS systems portably. +
- +
-Performance monitoring and tracing. Highlights of performance monitoring include identification of poor and suspicious SQL, with explain plan support, and identifying which web pages the SQL ran on. +
- +
-  +
- +
-12. Download +
- +
-You can download ADOdb from sourceforge. ADOdb uses a BSD style license. That means that it is free for commercial use, and redistribution without source code is allowed. +
- +
-  +
- +
-13. Resources+
  
 Oracle's Hitchhiker Guide to PHP Oracle's Hitchhiker Guide to PHP
v5/userguide/oracle_tutorial.txt · Last modified: 2019/12/29 21:36 by mnewnham