CakePHP SQLSTATE [HY000] [14]错误 [英] CakePHP SQLSTATE[HY000][14] error

查看:245
本文介绍了CakePHP SQLSTATE [HY000] [14]错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我当前的CakePHP 2.x应用程序升级到3.x.

I'm trying to upgrade my current CakePHP 2.x application to 3.x.

我修复了命名空间和文件夹结构问题。现在我有数据库的问题。在我的测试服务器中,我创建了相同的MySQL数据库并授予用户访问权限。然后我更改了 config\app.php 配置文件。但是当我尝试我的应用程序,我得到以下错误。会有什么问题?

I fixed namespace and folder structure issues. Now I have problems with database. In my test server, I created same MySQL database and grant access to users. Then I changed config\app.php configuration file. But when I try my application I get following error. What would be the problem ? It seems like Cakephp tries to use Sqlite but I use MySQL ?

里面 config\app.php

'Datasources' => [
    'default' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'persistent' => false,
        'host' => 'localhost',
        /**
         * CakePHP will use the default DB port based on the driver selected
         * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
         * the following line and set the port accordingly
         */
        //'port' => 'nonstandard_port_number',
        'username' => 'myuser',
        'password' => 'mypass',
        'database' => 'mydatabase',
        'encoding' => 'utf8',
        'timezone' => 'UTC',
        'cacheMetadata' => true,

        /**
         * Set identifier quoting to true if you are using reserved words or
         * special characters in your table or column names. Enabling this
         * setting will result in queries built using the Query Builder having
         * identifiers quoted when creating SQL. It should be noted that this
         * decreases performance because each query needs to be traversed and
         * manipulated before being executed.
         */
        'quoteIdentifiers' => false,
    ],
],

错误

Error: [PDOException] SQLSTATE[HY000] [14] unable to open database file
Request URL: /mycontroller/
Stack Trace:
#0 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php(48): PDO->__construct('sqlite:/var/www...', NULL, NULL, Array)
#1 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Database/Driver/Sqlite.php(61): Cake\Database\Driver\Sqlite->_connect('sqlite:/var/www...', Array)
#2 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Database/Schema/BaseSchema.php(46): Cake\Database\Driver\Sqlite->connect()
#3 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Database/Dialect/SqliteDialectTrait.php(169): Cake\Database\Schema\BaseSchema->__construct(Object(Cake\Database\Driver\Sqlite))
#4 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Database/Schema/Collection.php(52): Cake\Database\Driver\Sqlite->schemaDialect()
#5 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Database/Schema/CachedCollection.php(44): Cake\Database\Schema\Collection->__construct(Object(Cake\Database\Connection))
#6 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Database/Connection.php(319): Cake\Database\Schema\CachedCollection->__construct(Object(Cake\Database\Connection), true)
#7 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/debug_kit/src/Model/Table/LazyTableTrait.php(40): Cake\Database\Connection->schemaCollection()
#8 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/debug_kit/src/Model/Table/RequestsTable.php(43): DebugKit\Model\Table\RequestsTable->ensureTables(Array)
#9 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/ORM/Table.php(285): DebugKit\Model\Table\RequestsTable->initialize(Array)
#10 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/ORM/TableRegistry.php(196): Cake\ORM\Table->__construct(Array)
#11 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/debug_kit/src/Routing/Filter/DebugBarFilter.php(186): Cake\ORM\TableRegistry::get('DebugKit.Reques...')
#12 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Event/EventManager.php(389): DebugKit\Routing\Filter\DebugBarFilter->afterDispatch(Object(Cake\Event\Event), Object(Cake\Network\Request), Object(Cake\Network\Response))
#13 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Event/EventManager.php(355): Cake\Event\EventManager->_callListener(Array, Object(Cake\Event\Event))
#14 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Event/EventManagerTrait.php(78): Cake\Event\EventManager->dispatch(Object(Cake\Event\Event))
#15 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(92): Cake\Routing\Dispatcher->dispatchEvent('Dispatcher.afte...', Array)
#16 /var/www/vhosts/example.com/httpdocs/webroot/index.php(37): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#17 {main}


推荐答案

如果你在stacktrace看得更近一点,你会注意到这不是来自你的应用程序连接,从DebugKit插件,它默认情况下使用SQLite存储面板和请求的详细信息,很可能目标目录/文件是不可写的。

If you look a little closer at the stacktrace, you'll notice that this doesn't stem from your apps connections, but from the DebugKit plugin, which by default uses SQLite for storing panel and request details, and most probably the target directory/file isn't writable.

Cookbook> DebugKit

Cookbook > DebugKit


[...]

[...]

默认情况下,DebugKit使用小SQLite数据库在您的应用程序的 / tmp 目录中以存储面板数据。如果你想让DebugKit将数据存储在其他地方,你应该定义一个 debug_kit 连接。

By default, DebugKit uses a small SQLite database in your application’s /tmp directory to store the panel data. If you’d like DebugKit to store its data elsewhere, you should define a debug_kit connection.

默认情况下,DebugKit将面板数据存储到应用程序的 tmp 目录中的SQLite数据库中。如果您不能安装 pdo_sqlite ,您可以通过在 debug_kit 中定义 debug_kit 连接,将DebugKit配置为使用不同的数据库c $ c> config / app.php 文件。

By default DebugKit will store panel data into a SQLite database in your application’s tmp directory. If you cannot install pdo_sqlite, you can configure DebugKit to use a different database by defining a debug_kit connection in your config/app.php file.

[...]

这篇关于CakePHP SQLSTATE [HY000] [14]错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆