In PHP getting “Class 'PDO' not found” error while trying to connect to Oracle DB

試著忘記壹切 提交于 2019-12-24 04:24:13

问题


I am trying to connect to my oracle database using PDO but I am getting Class PDO not found error. I have checked that PDO is enabled and it appears so. Still I am not able to trace why I am getting this error. Here is my configure command,

cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" 
"--with-snapshot-template=d:\php-sdk\snap_5_2\vc6\x86\template" 
"--with-php-build=d:\php-sdk\snap_5_2\vc6\x86\php_build" 
"--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" 
"--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared"

PHP ver : 5.2.8 Oracle: 10.2

This is the code I am using to connect to the db.

try{
    $conn = new PDO("oci:dbname=".$oc_db,$oc_user,$oc_pass);
}catch(PDOException $e){
    echo ($e->getMessage());
}

Can there be any other reason that I am getting this error? Any help appreciated.


回答1:


This generally means the PDO extension in question isn't compiled and set up so PHP can use it. What operating system are you compiling PHP on?

I'm not sure if PDO core module is compiled if you only specify to compile the oracle extension of it (PDO-OCI).

You should check out the PHP manual regarding how to install and enable the PDO module.

You should look at these sites: http://is.php.net/manual/en/pdo.installation.php http://is.php.net/manual/en/ref.pdo-oci.php




回答2:


Check my question I troubleshoot this and other errors but then Im stuck, No records found ...Agiletoolkit and Oracle. Grid/CRUD elements

My Oracle connection string in agiletoolkit config-default.php file looks like this:

$config['dsn']= array( 'oci:dbname=localhost/MYDATABASE', 'MYUSER', 'MYPASSWORD' );

To fix the driver not found error, I enabled extension=php_pdo_oci8.dll in the php.ini file from my apache installation.

Then there was an error about a missing "oci.php", to solve that I had to create my own file like this:

class DB_dsql_oci extends DB_dsql {
    function limit($cnt,$shift=0){
        $cnt+=$shift;

    $this->where('NUM_ROWS>=',$shift);
        $this->where('NUM_ROWS<',$cnt);
        return $this;
    }
    function render_limit(){
        return '';
    }
}

and placed it at: ...atk4\lib\DB\dsql

To fix the special chars error from oracle , I set line 59 on /atk4/lib/DB/dsql.php to empty string like this: public $bt='';

I manage to run the database test, and it says "Successfully connected to database."



来源:https://stackoverflow.com/questions/1436264/in-php-getting-class-pdo-not-found-error-while-trying-to-connect-to-oracle-d

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