CakePHP可以和Oracle一起作为数据库使用吗?

wpcxdonn  于 2023-04-05  发布在  Oracle
关注(0)|答案(1)|浏览(146)

我试图在CakePHP 4项目上从MySQL切换到Oracle数据库,这似乎是不可能的。我使用这个驱动程序CakePHP Oracle Driver,我安装了instantcliente 19.6,oci 8 -2.2.0(用于php7.4.33)和pdo_oci,因为它是在存储库上解释。
我只能使用手动构建的查询,如下所示:

$sql = $this->oracleConnection
            ->newQuery()
            ->select('USERS.LOCKED, USERS.LOCK_TYPE')
            ->from('USERS')
            ->where('USERS.USERNAME = \'' . $username . '\' AND ROWNUM = 1')
            ->order([]);

但是CakePHP的默认方法,如find()和get(),会抛出如下错误:ORA-00911:无效字符
发现错误的人:

$blockedUser = $this->blockedUser->find('all', [
            'conditions' => [
                'BlockedUsers.blocked_until >' => FrozenTime::now(),
                'BlockedUsers.username' => $username,
            ],
        ])->first();

和它发送并获取错误的查询:

SELECT *
FROM (
  SELECT cake_paging.*, (ROWNUM) AS _cake_page_rownum_
  FROM (
    SELECT BlockedUsers.ID AS BlockedUsers__ID,
           BlockedUsers.USERNAME AS BlockedUsers__USERNAME,
           BlockedUsers.OS AS BlockedUsers__OS,
           BlockedUsers.USER_AGENT AS BlockedUsers__USER_AGENT, 
           BlockedUsers.CREATED AS BlockedUsers__CREATED,
           BlockedUsers.BLOCKED_UNTIL AS BlockedUsers__BLOCKED_UNTIL
    FROM   blocked_users BlockedUsers
    WHERE (BlockedUsers.blocked_until > :c0 AND BlockedUsers.username = :c1)
  ) cake_paging
) cake_paging_out
WHERE cake_paging_out."_cake_page_rownum_" <= 1

BLOCKED_USERS表:
BLOCKED_USERS
这里还有我从app.php得到的连接:

'default' => [
            'className' => 'CakeDC\OracleDriver\Database\OracleConnection',
            'driver' => 'CakeDC\OracleDriver\Database\Driver\OracleOCI',
            'persistent' => false,
            'host' => 'myhost',
            'port' => 'myport',
            'username' => 'myusername',
            'password' => 'mypassword',
            'database' => 'myDB',
            'sid' => 'mySID',
            'encoding' => 'WE8ISO8859P1',
            'timezone' => '+1:00',
            'flags' => [],
            'cacheMetadata' => true,
            'log' => false,
            'quoteIdentifiers' => false,
            'server_version' => 10,
            'url' => env('DATABASE_URL', null),
        ],

我已经尝试在app.php中测试多种类型的连接,卸载和安装php和扩展.所有这一切我问自己,如果我做错了什么,或者是不是可能的?

vuktfyat

vuktfyat1#

错误产生于:

(ROWNUM) AS _cake_page_rownum_

它应该是:

(ROWNUM) AS "_cake_page_rownum_"

因为_对于未加引号的标识符不是有效的前导字符。
ORM通常在它们生成的代码中使用带引号的标识符;你的代码(除了一个例外)没有使用任何看起来很奇怪的带引号的标识符。

相关问题