在 PHP 中尝试连接到 Oracle DB 时出现“找不到类‘PDO’”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1436264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In PHP getting "Class 'PDO' not found" error while trying to connect to Oracle DB
提问by Chantz
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,
我正在尝试使用 PDO 连接到我的 oracle 数据库,但出现Class PDO not found 错误。我已经检查过 PDO 是否已启用,并且看起来如此。我仍然无法追踪我收到此错误的原因。这是我的配置命令,
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
PHP 版本:5.2.8 甲骨文: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.
我收到此错误还有其他任何原因吗?任何帮助表示赞赏。
采纳答案by Kristinn ?rn Siguresson
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?
这通常意味着有问题的 PDO 扩展没有被编译和设置,所以 PHP 可以使用它。你在什么操作系统上编译 PHP?
I'm not sure if PDO core module is compiled if you only specify to compile the oracle extension of it (PDO-OCI).
如果您只指定编译它的 oracle 扩展(PDO-OCI),我不确定是否编译了 PDO 核心模块。
You should check out the PHP manual regarding how to install and enable the PDO module.
您应该查看有关如何安装和启用 PDO 模块的 PHP 手册。
You should look at these sites: http://is.php.net/manual/en/pdo.installation.phphttp://is.php.net/manual/en/ref.pdo-oci.php
您应该查看这些站点: http://is.php.net/manual/en/pdo.installation.php http://is.php.net/manual/en/ref.pdo-oci.php
回答by Adrian
Check my question I troubleshoot this and other errors but then Im stuck, No records found ...Agiletoolkit and Oracle. Grid/CRUD elements
检查我的问题,我解决了这个和其他错误,但后来我卡住了, 没有找到记录...Agiletoolkit 和 Oracle。网格/CRUD 元素
My Oracle connection string in agiletoolkit config-default.php file looks like this:
我在agiletoolkit config-default.php 文件中的Oracle 连接字符串如下所示:
$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.
为了修复找不到驱动程序的错误,我在 apache 安装的 php.ini 文件中启用了 extension=php_pdo_oci8.dll。
Then there was an error about a missing "oci.php", to solve that I had to create my own file like this:
然后出现了一个关于缺少“oci.php”的错误,为了解决这个问题,我必须像这样创建自己的文件:
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
并将其放置在:...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='';
为了修复 oracle 的特殊字符错误,我将 /atk4/lib/DB/dsql.php 上的第 59 行设置为空字符串,如下所示: public $bt='';
I manage to run the database test, and it says "Successfully connected to database."
我设法运行数据库测试,并显示“已成功连接到数据库”。