Laravel - MySql connection help

I have added the Laravel framework to my site but cannot connect to my MySql database.
config > database I have
‘host’ => env(‘DB_HOST’, ‘127.0.0.1’),
‘port’ => env(‘DB_PORT’, ‘3306’),

and in .env file I have

DB_HOST=127.0.0.1
DB_PORT=33060

and get the error message SQLSTATE[HY000] [2002] Connection refused (SQL: SELECT * FROM users)

When I change the host to localhost in both files I get the error message

SQLSTATE[HY000] [2002] No such file or directory (SQL: SELECT * FROM users)


For reference I created the following route in app > http > routes.php and in routes > web.php

Route::get(‘view-records’,‘StudViewController@index’);

I created the following controller in app > http > controllers > StudViewController.php

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Http\Requests; use App\Http\Controllers\Controller; class StudViewController extends Controller { public function index() { $users = DB::select('SELECT * FROM users'); return view('stud_view',['users'=>$users]); } } but the view gives the error messages above. Can you help please.

Thanks for your response. I read a recent post regarding SQL help and found that replacing localhost in both files with sql105.epizy.com has worked. I am now connected

1 Like