gpt4 book ai didi

php - AWS RDS 数据库的 CakePHP3 应用程序错误

转载 作者:行者123 更新时间:2023-11-30 22:17:01 25 4
gpt4 key购买 nike

我最初为我的 cakephp 3 应用程序使用本地 mysql 数据库,一切正常。我正在部署我的 cakephp3 应用程序,所以我创建了一个 RDS MySql 实例并将其连接到 MySql 工作台,并将我之前拥有的数据库复制到 RDS 数据库。我的 app.php 中的设置是这样的。

要定义我的常量

if (!defined('RDS_HOSTNAME')) {
define('RDS_HOSTNAME', $_SERVER['myendpoint.us-west-1.rds.amazonaws.com']);
define('RDS_USERNAME', $_SERVER['myusername']);
define('RDS_PASSWORD', $_SERVER['mypassword']);
define('RDS_DB_NAME', $_SERVER['my_db']);
}

然后在 app.php 文件的数据源部分

'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => RDS_HOSTNAME,
/**
* 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' => 'non_standard_port_number',
'username' => RDS_USERNAME,
'password' => RDS_PASSWORD,
'database' => RDS_DB_NAME,
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,

在 AWS 控制台上,它显示我已连接到 RDS 实例。但是,当我尝试注册/登录时,出现 CakePHP 内部错误。然后我检查了错误日志,并在我的 error.log 文件中发现了这一点。

2016-06-20 17:25:35 Error: [PDOException] SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
Request URL: /users/register
Referer URL: http://localhost:8765/
Client IP: 127.0.0.1
Stack Trace:
#0 /home/danielparkk/Desktop/SubReminder/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php(47): PDO->__construct('mysql:host=;por...', NULL, NULL, Array)
#1 /home/danielparkk/Desktop/SubReminder/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php(90): Cake\Database\Driver\Mysql->_connect('mysql:host=;por...', Array)

我不明白我做错了什么?当我切换回我拥有的数据库的本地副本时,一切都正常运行。任何帮助将不胜感激。

===================编辑=======================

2016-06-21T00:22:17.815360Z 24 [Note] Access denied for user 'root'@'108-83-57-226.lightspeed.irvnca.sbcglobal.net' (using password: NO)
2016-06-21T00:34:38.776248Z 26 [Note] Aborted connection 26 to db: 'subscriptions_db' user: 'root' host: '108-83-57-226.lightspeed.irvnca.sbcglobal.net' (Got timeout reading communication packets)
2016-06-21T00:34:42.872265Z 25 [Note] Aborted connection 25 to db: 'subscriptions_db' user: 'root' host: '108-83-57-226.lightspeed.irvnca.sbcglobal.net' (Got timeout reading communication packets)

在我的实例的 AWS 控制台中读取错误日志时,我得到了这个输出。坦率地说,这是我第一次使用 RDS,所以我不知道这意味着什么,但它可能对其他人有帮助。

最佳答案

You should only write this no need to $_SERVER. i am also connect cakephp 3.01 AWS RDS below is my code.

   'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'yourendpoint.us-west-1.rds.amazonaws.com',
'username' => 'rdsusername',
'password' => 'rdspassword',
'database' => 'rdsdatabasename',
'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,

/**
* During development, if using MySQL < 5.6, uncommenting the
* following line could boost the speed at which schema metadata is
* fetched from the database. It can also be set directly with the
* mysql configuration directive 'innodb_stats_on_metadata = 0'
* which is the recommended value in production environments
*/
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
]
],

关于php - AWS RDS 数据库的 CakePHP3 应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37933898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com