Я использую модель Eloquent для получения данных из базы данных MySQL, работающей на AWS.Когда я пытаюсь перенести базу данных, она работает, поэтому я знаю, что соединение не является проблемой.Кроме того, я экспортировал свои модели из существующей БД, и это тоже хорошо работало.Тем не менее, когда я пытаюсь использовать модель в контроллере, я получаю SQLSTATE [HY000] [2002] Соединение отклонено (SQL: выберите * из about
) (примерно такое имя таблицы).
РЕДАКТИРОВАТЬ: После прохождения трассировки стека кажется, что установлено неправильное соединение?Не уверен, почему аргумент "mysql: host = 127.0.0.1; port = 3306; dbname = laravel", когда мой env указывает другое соединение?Может ли это быть как-то связано с проблемой?
*/
public function connect(array $config)
{
$dsn = $this->getDsn($config);
$options = $this->getOptions($config);
// We need to grab the PDO options that should be used while making the brand
// new connection instance. The PDO options control various aspects of the
// connection's behavior, and some might be specified by the developers.
$connection = $this->createConnection($dsn, $config, $options);
if (! empty($config['database'])) {
$connection->exec("use `{$config['database']}`;");
}
$this->configureEncoding($connection, $config);
// Next, we will check to see if a timezone has been specified in this config
// and if it has we will issue a statement to modify the timezone with the
// database. Setting this DB timezone is an optional configuration item.
$this->configureTimezone($connection, $config);
$this->setModes($connection, $config);
return $connection;
}
/**
* Set the connection character set and collation.
*
Arguments
"mysql:host=127.0.0.1;port=3306;dbname=laravel"
array:15 [▶]
array:5 [▶]
Вот моя конфигурация .env
DB_CONNECTION=mysql
DB_HOST=***.***.us-east-1.rds.amazonaws.com
DB_PORT=3306
DB_DATABASE=sprCoffee
DB_USERNAME=admin
DB_PASSWORD=password
Вот мой класс модели.
<?php
/**
* Created by Reliese Model.
* Date: Tue, 11 Jun 2019 21:26:12 +0000.
*/
namespace App\Models;
use Reliese\Database\Eloquent\Model as Eloquent;
/**
* Class About
*
* @property int $id
* @property string $description
* @property string $image
* @property string $name
* @property int $position
*
* @package App\Models
*/
class About extends Eloquent
{
protected $table = 'about';
public $incrementing = false;
public $timestamps = false;
protected $casts = [
'id' => 'int',
'position' => 'int'
];
protected $fillable = [
'description',
'image',
'name',
'position'
];
}
Здесьмоя конфигурация .env
DB_CONNECTION=mysql
DB_HOST=***.***.us-east-1.rds.amazonaws.com
DB_PORT=3306
DB_DATABASE=sprCoffee
DB_USERNAME=admin
DB_PASSWORD=password
Главное, что при переносе базы данных она создает новую таблицу переноса в моей базе данных, поэтому я не думаю, что мое соединение является проблемой.У меня есть группа безопасности в RDS, чтобы принимать входящие и исходящие от "мой IP"