laravel でMAMPのmysqlへの接続ができません
環境は、ローカル環境のMAMPです。
エラーメッセージ
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from people)
<web.php>
Route::get('hello','HelloController@index');
<HelloController.php>
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class HelloController extends Controller { public function index(Request $request) { $items = DB::select('select * from people'); return view('hello.index',['items' => $items]); } }
<index.blade.php>
<html> <head> </head> <body> @foreach ($items as $item) {{$item->name}} {{$item->mail}} {{$item->age}} @endforeach </body> </html>
<.env>
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD=root
<database.php>
'default' => env('DB_CONNECTION', 'mysql'), 'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST','127.0.0.1'), 'port' => env('DB_PORT','3306'), 'database' => env('DB_DATABASE','laravel'), 'username' => env('DB_USERNAME','root'), 'password' => env('DB_PASSWORD','root'), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ],
回答1件
あなたの回答
tips
プレビュー