Laravel 5 Connection拒绝了

时间:2016-06-24 05:01:50

标签: php laravel laravel-5.2

我是Laravel的新手,我似乎无法连接到数据库。这是我的配置

  • Mac OSX El Capitan
  • MAMP Pro

我总是收到错误 SQLSTATE [HY000] [2002]拒绝连接。 我在数据库应用程序中有 my_users 表。顺便说一下,我在youtube上关注本教程。 Link here

.ENV

APP_ENV=local
APP_DEBUG=true
APP_KEY=LVwc8N06OepmCfptIcATzNxN2pkYJJwf

DB_HOST=localhost
DB_DATABASE=application   
DB_USERNAME=root
DB_PASSWORD=root

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=localhost
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

my_users.php(型号)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class my_users extends Model
{
    //
}

routes.php文件

<?php

use App\my_users;

Route::get('/', function () {

    $users = my_users::all();

});

database.php中

return [



    'fetch' => PDO::FETCH_CLASS,


    'default' => env('DB_CONNECTION', 'mysql'),



    'connections' => [

        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => database_path('database.sqlite'),
            'prefix'   => '',
        ],

        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

        'pgsql' => [
            'driver'   => 'pgsql',
            'host'     => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset'  => 'utf8',
            'prefix'   => '',
            'schema'   => 'public',
        ],

        'sqlsrv' => [
            'driver'   => 'sqlsrv',
            'host'     => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset'  => 'utf8',
            'prefix'   => '',
        ],

    ],


    'migrations' => 'migrations',


    'redis' => [

        'cluster' => false,

        'default' => [
            'host'     => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port'     => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],

];

0 个答案:

没有答案