kaizenCoder
kaizenCoder

Reputation: 2229

Oracle PHP PDO exception: could not find driver

I'm trying to hack together a script to connect to a remote oracle database and execute a simple query

Through extensive searches I found the following script:

<?

$tns = "
    (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = bogus.com.au)(PORT = 1521))
        (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = myDB )
        )
    )
";


$pdo_string = 'oci:dbname='.$tns;

try {
    $dbh = new PDO($pdo_string, 'test', 'fake');
} catch (PDOException $e) {
    echo "Failed to obtain database handle: " . $e->getMessage();
    exit;
}

$query = "SELECT * FROM someTable";

$stmt = $dbh->prepare($query);

if ($stmt->execute()) {
    echo "<h4>$query</h4>";
    echo "<pre>";
    while ($row = $stmt->fetch()) {
        print_r($row);
    }
    echo "</pre>";
}

?>

However I'm getting the error could not find driver. So I did:

foreach(PDO::getAvailableDrivers() as $driver)
    echo $driver, '<br>';

Which returned:

mysql
odbc
sqlite

That tells me that I do have the driver installed, yes?

What am I doing wrong? (Admittedly I have little to no knowledge of PHP with Oracle databases so maybe I'm missing the blatantly obvious..)

Upvotes: 3

Views: 34750

Answers (2)

Ibrahim.I
Ibrahim.I

Reputation: 329

You have to configure your server to enable the PDO_OCI extension.

Go to php.ini and find the line extension=php_pdo_oci.dll and remove the comma ; from its start then restart your apache service.

Upvotes: 0

Emery King
Emery King

Reputation: 3534

You have to install Oracle adapter in PDO:

http://php.net/manual/en/ref.pdo-oci.php

Upvotes: 2

Related Questions