Oracle

From RadPHP XE2 Documentation
Jump to: navigation, search

Contents

Initial Setup

To get PHP and Oracle working together, follow these steps:

  1. Get Instant Client from oracle.com/technetwork/database/features/instant-client/index-097480.html.
  2. Extract the archive somewhere.
  3. Get your system to recognize the .dll files in Instant Client folder. You can do it different ways:
    • Copy all .dll files in Instant Client folder into your Windows\System32 directory.
    • Point ORACLE_HOME to Instant Client folder. Check orafaq.com/wiki/ORACLE_HOME for more information.
  4. Uncomment (remove the ; at the beginning) the following line on RadPHP php.ini.template file:
    ;extension=php_oci8.dll

Usage

Data Explorer Setup

When you set up a connection to an Oracle database from the Data Explorer, you must fill Database Name property with the database server address and database name, separated by a slash (/). For example: 127.0.0.1/database.

Database Setup

To use a Database component with Oracle, set it up so it uses Oracle driver:

  • DriverName: oracle.

Do not forget to fill also the rest of the basic information.

Work With PHP

// Set Connection Data
$database = 'database';			// Server address and database name like this: //server/database.
$user = 'user';				// Username to access the database.
$password = 'password';			// Password for the user.
 
// Establish Connection
$connection = oci_connect($user, $password, $server);
 
// Connection Test
if (!$connection)
    echo 'Oracle Database could not be reached';
else
    echo 'Succesfully connected to Oracle Database';
 
// Perform a Query
$sql = "SELECT * FROM table";
$statement = oci_parse ($connection, $sql);
oci_execute ($statement);
while ($row = oci_fetch_assoc($statement)) 
{
    print_r($row);
}
oci_free_statement($statement);

See Also

Personal tools