php - pdo_oci driver not found but is listed in available drivers


I am trying to connect to an Oracle Database 11g XE running on windows from a remote Ubuntu 14.04 server using PDO_OCI in php. I followed this guide (numerous times) and keep getting the following error:

could not find driver

However when I call PDO::getAvailableDrivers() it gives me this:

Array ( [0] => mysql [1] => oci [2] => sqlite )

Note: oci wasn't there before I followed the guide in the link above.

All of the other tutorials I could find were basically the same thing.

I have the Oracle instant client installed (version 11.1). The latest version was not even getting the driver to show up in the list of available drivers.

Also I know that the driver which is used in this method is older but there are no step by step guides on how to get it working with the lastest one. I am new to Oracle Databases as well as php so step by step help would be greatly appreciated.

UPDATE: I figured out the driver problem. It was in my php code, and something very silly. I am posting for the benefit of others.

My original code had "OCI" in capital letters when setting the connection.

$tns = "  
      (ADDRESS = (PROTOCOL = TCP)(HOST = myIP)(PORT = 1521))

$pdo = new PDO('OCI:dbname='.$tns ,'username','password'); // Capital 'OCI' here is WRONG so changed to 'oci:dbname='
} catch(PDOException $e){
    echo $e->getMessage();


However, I am having problems querying the Database. It seems nothing is happening. I have allowed the port 1521 in the Windows firewall for both incoming and outgoing. Any suggestion?

Here is my php code:

$stmt = $pdo->prepare("SELECT * FROM `PDO`;");
$result = $stmt->fetchColumn(0);
echo $result;

The tablePDO only has one column with one row.

Does the Oracle database need to be configured to allow for remote connections?




There were two problems with my PHP code. 1) The way the PDO connection was initiated was incorrect ... see update in original post. That solved my driver problem.

2) Oracle doesn't seem to like the backtick character, unlike MySQL. So I had to remove them from my query to look like this

$stmt = $pdo->prepare("SELECT * FROM PDO"); // Originally was SELECT * FROM `PDO`
$result = $stmt->fetchColumn(0);
echo $result; 

This solved my database querying problem.

People are also looking for solutions to the problem: regex - get the words between two specific characters in php


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.