Oracle PHP PDO exception: could not find driver

蹲街弑〆低调 提交于 2020-07-16 05:01:36

问题


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..)


回答1:


You have to install Oracle adapter in PDO:

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




回答2:


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.



来源:https://stackoverflow.com/questions/15514665/oracle-php-pdo-exception-could-not-find-driver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!