Oracle
For more information on using advanced functionality in the Oracle driver, read the Advanced Oracle Tutorial
oci8
Specification
Driver Name | oci8 |
---|---|
Data Provider | oracle |
Status | Active1) |
Windows | Yes |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
Alternatives
See Also
This is the preferred driver for connecting to Oracle databases Despite its name, this driver supports Oracle databases up to and including Oracle 11.
This is currently the only supported driver when using PHP 7
Driver Specific Methods
Non portable methods are not declared in the base class. Use of these methods in portable code will cause a fatal error when used with other drivers.
The following non-portable methods are available to this driver
Method | Description |
---|---|
bind() | A fast way of updating records |
executeCursor() | Returns a cursor to procedure as a handle |
Connection Examples
a. PHP and Oracle reside on the same machine, use default SID, with non-persistent connections:
$conn = NewADOConnection('oci8'); $conn->connect(false, 'scott', 'tiger');
b. TNS Name defined in tnsnames.ora (or ONAMES or HOSTNAMES), eg. 'myTNS':
$conn = NewADOConnection('oci8'); $conn->connect(false, 'scott', 'tiger', 'myTNS');
or
$conn->connect('myTNS', 'scott', 'tiger');
c. Host Address and SID
$conn->connectSID = true; $conn->connect('192.168.0.1', 'scott', 'tiger', 'SID');
d. Host Address and Service Name
$conn->connect('192.168.0.1', 'scott', 'tiger', 'servicename');
e. Oracle connection string:
$cstr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) (HOST=$host) (PORT=$port) ) (CONNECT_DATA=(SID=$sid) ) )"; $conn->connect($cstr, 'scott', 'tiger');
f. ADOdb data source names (dsn):
$dsn = 'oci8://user:pwd@tnsname/?persist'; # persist is optional $conn = ADONewConnection($dsn); # no need for connect/pConnect
$dsn = 'oci8://user:pwd@host/sid'; $conn = ADONewConnection($dsn);
$dsn = 'oci8://user:pwd@/'; # oracle on local machine $conn = ADONewConnection($dsn);
With ADOdb data source names, there is no need to call connect()
or pConnect()
as this is done automatically.
Date Format
By default, after connection the following SQL is issued:
"ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'"
The default value for NLS_DATE_FORMAT
is YYYY-MM-DD
. To include time as well, use RRRR-MM-DD HH24:MI:SS
or set the value to empty to disable this action.
Auto-Increment Column
Auto-increment support for Oracle databases is implemented by creating an on-insert trigger that retrieves a sequence number from a sequence SEQ_ + table name . This is done by default.
If you have long table names then the generated trigger name can exceed the maximum allowed length. To prevent this, use the class variable useCompactAutoIncrements
. This will change the trigger name to a generated CRC value of the name.
Example using the table name "customer_delivery_address"
By default, the trigger name would be SEQ_CUSTOMER_DELIVERY_ADDRESS which exceeds the 16 character name for sequences. By setting $db→useCompactAutoIncrements=true
, the sequence name is changed to SEQ_401703491
Accessing the trigger in your code
$db->useCompactAutoIncrements=true; $tab = 'customer_delivery_address'; $tab = sprintf('SEQ_%u',crc32(strtolower($tab))); print $tab; //prints SEQ_401703491
Session Mode
From ADOdb V5.23.0, You can use external (OCI_CRED_EXT)
or privileged (OCI_SYSOPER or OCI_SYSDBA
) sessions via the setConnectionParameter() method, prior to establishing a connection.
$db = ADONewConnection('oci8'); $db->setConnectionParameter('session_mode', OCI_CRED_EXT); $db->connect(false, 'scott', 'tiger', 'myTNS');
oci8po
Specification
Driver Name | oci8po |
---|---|
Data Provider | oracle |
Status | Active2) |
Windows | Yes |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
This driver extends the oci8 driver and mostly provides compatibility with MySQL databases which use the ? placeholder for bind params.
If you are migrating code or writing portable code, consider using the param() command to write portable placeholders.
A second difference to this driver is that it does not create a sequence to emulate auto-increment fields. You must provide the functionality yourself if you need it.
oci805
Specification
Driver Name | oci805 |
---|---|
Data Provider | oracle |
Status | Inactive3) |
Windows | Yes |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
This driver provides an undocumented enhancement to the oci8 driver
It adds a FIRST_ROWS optimizer hint to the SQL statements executed with selectLimit. Note that FIRST_ROWS has been deprecated in Oracle 9.2, and is retained for backwards compatibility.
oci8quercus
Specification
Driver Name | oci8quercus |
---|---|
Data Provider | oracle |
Status | Inactive4) |
Windows | Yes |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
This driver provides an undocumented enhancement to the oci8 driver. The differences in the driver relate solely to the use of cursors in stored procedures. This may be related to information in the function executeCursor and the Oracle Tutorial. If you have the appropriate expertise and the time to investigate and explain these drivers, let us know.
oracle
Support for oracle databases versions 7 and lower was removed in PHP version 5.1. In ADOdb version 6, the Oracle driver will be removed
Specification
Driver Name | oracle |
---|---|
Data Provider | oracle |
Status | Obsolete5) |
Windows | Yes |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | No |
This driver provided support to oracle 7 and lower databases. The driver is obsolete, and not supported by PHP and will be removed in ADOdb version 6.0.