CakePHP 4.4.14连接Oracle遇方法声明兼容错误求助
CakePHP连接Oracle数据库时出现方法声明不兼容的致命错误
我基于CakePHP创建了一个项目,尝试连接公司提供的Oracle数据库实例。从CakeDC/cakephp-oracle-driver仓库安装了CakePHP 4驱动,并按照文档说明完成配置后,运行项目出现以下致命错误:
Fatal error: Declaration of CakeDC\OracleDriver\Database\OCI8\OCI8Connection::query($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null) must be compatible with PDO::query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs): PDOStatement|false in E:\my-cake-project\vendor\cakedc\cakephp-oracle-driver\src\Database\OCI8\OCI8Connection.php on line 130
我已按照仓库文档要求启用了php.ini中所有必要的扩展和Oracle驱动,相关配置如下:
已启用的PHP扩展(php.ini)
extension=curl ;extension=ffi ;extension=ftp extension=fileinfo ;extension=gd extension=gettext ;extension=gmp extension=intl ;extension=imap extension=mbstring extension=exif ; Must be after mbstring as it depends on it extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client extension=oci8_19 ; Use with Oracle Database 19 Instant Client ;extension=odbc ;extension=openssl ;extension=pdo_firebird extension=pdo_mysql extension=pdo_oci ;extension=pdo_odbc ;extension=pdo_pgsql extension=pdo_sqlite ;extension=pgsql ;extension=shmop ; The MIBS data available in the PHP distribution must be installed. ; See https://www.php.net/manual/en/snmp.installation.php ;extension=snmp ;extension=soap ;extension=sockets ;extension=sodium extension=sqlite3 ;extension=tidy ;extension=xsl extension=zip
Application.php配置
public function bootstrap(): void { // Call parent to load bootstrap from files. parent::bootstrap(); if (PHP_SAPI === 'cli') { $this->bootstrapCli(); } else { FactoryLocator::add( 'Table', (new TableLocator())->allowFallbackClass(false) ); } /* * Only try to load DebugKit in development mode * Debug Kit should not be installed on a production system */ if (Configure::read('debug')) { $this->addPlugin('DebugKit'); } // Added oracle driver plugin $this->addPlugin(\CakeDC\OracleDriver\Plugin::class, ['bootstrap' => true]); } protected function bootstrapCli(): void { $this->addOptionalPlugin('Cake/Repl'); $this->addOptionalPlugin('Bake'); $this->addPlugin('Migrations'); // Added oracle driver plugin $this->addPlugin(\CakeDC\OracleDriver\Plugin::class, ['bootstrap' => true]); }
数据源配置(./config/app.php)
'Datasources' => [ /* * These configurations should contain permanent settings used * by all environments. * * The values in app_local.php will override any values set here * and should be used for local and per-environment configurations. * * Environment variable based configurations can be loaded here or * in app_local.php depending on the applications needs. */ 'default' => [ 'className' => 'CakeDC\OracleDriver\Database\OracleConnection', 'driver' => 'CakeDC\OracleDriver\Database\Driver\OracleOCI', # For OCI8 // 'driver' => 'CakeDC\\OracleDriver\\Database\\Driver\\OraclePDO', # For PDO_OCI 'persistent' => true, // Database persistent connection between http requests 'host' => 'oracle.xyz.com', // Database host name or IP address 'port' => 1111, // Database port number (default: 1521) 'username' => 'myoracle', // Database username 'password' => 'xxxxxxxxxx', // Database password 'database' => 'myoracle_db', // Database name (maps to Oracle's `SERVICE_NAME`) 'sid' => 'ORCL', // Database System ID (maps to Oracle's `SID`) 'instance' => '', // Database instance name (maps to Oracle's `INSTANCE_NAME`) 'pooled' => '', // Database pooling (maps to Oracle's `SERVER=POOLED`) 'flags' => [], // Database low level parameters for OCI or PDO connection. Auto-generated by default 'encoding' => '', // Database charset (default same as database charset) 'init' => [], // Array of queries executed at connection 'cacheMetadata' => true, // Enable cakephp schema caching 'server_version' => 19, // Oracle server numeric version ex.: 11,12,19 'autoincrement' => true, // Enable autoincrement insteadof custom triggers in case of oracle 12+ ],
环境信息
> PHP 8.2.7 > CakePHP 4.4.14 Strawberry > Oracle Database 19.3 > Oracle Client 19.19 > Windows Platform
我是CakePHP新手,不确定哪里操作有误,MySQL连接能正常工作,希望得到帮助以顺畅连接Oracle数据库。
内容的提问来源于stack exchange,提问作者Jahir509
相关产品推荐
相关产品推荐

