XAMPP - Oracle Driver Setup (v12)

Daniel Opitz
Daniel Opitz
21 Mar 2017

Last update: 08.01.2020

Requirements

This driver requires the Microsoft Visual C++ Redistributable. The redistributable can easily be downloaded on the Microsoft website as x86 or x64 edition.

Notice: On a x64 computer the x86 AND the x64 version of the Visual C++ Redistributable setup must be installed.

Visual C++ Redistributable for Visual Studio

This setup is tested with PHP (32-Bit): 5.6, 7.0, 7.1, 7.2, 7.3 and with PHP (x64) 64-Bit: 7.4

Setup

Known issues

Especially the WAMP users reported that they still get the following error message:

PHP Warning: PHP Startup: Unable to load dynamic library 'oci8_12c'.

Make sure you downloaded the correct Oracle Instant Client, 32-bit or (x64) 64-bit.

You can also try to download the correct php_oci8 dll files from this page:

Connection test

<?php

error_reporting(E_ALL);

if (function_exists("oci_connect")) {
    echo "oci_connect found\n";
} else {
    echo "oci_connect not found\n";
    exit;
}

$host = 'localhost';
$port = '1521';

// Oracle service name (instance)
$db_name     = 'DBNAME';
$db_username = "USERNAME";
$db_password = "123456";

$tns = "(DESCRIPTION =
	(CONNECT_TIMEOUT=3)(RETRY_COUNT=0)
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = $host)(PORT = $port))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = $db_name)
    )
  )";
$tns = "$host:$port/$db_name";

try {
    $conn = oci_connect($db_username, $db_password, $tns);
    if (!$conn) {
        $e = oci_error();
        throw new Exception($e['message']);
    }
    echo "Connection OK\n";
    
    $stid = oci_parse($conn, 'SELECT * FROM ALL_TABLES');
    
    if (!$stid) {
        $e = oci_error($conn);
        throw new Exception($e['message']);
    }
    // Perform the logic of the query
    $r = oci_execute($stid);
    if (!$r) {
        $e = oci_error($stid);
        throw new Exception($e['message']);
    }
    
    // Fetch the results of the query
    while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {
        $row = array_change_key_case($row, CASE_LOWER);
        print_r($row);
        break;
    }
    
    // Close statement
    oci_free_statement($stid);
    
    // Disconnect
    oci_close($conn);
    
}
catch (Exception $e) {
    print_r($e);
}