I am using laravel on a live shared hosting and I am getting the error above despite using the right database connection credentials. I have edited the .env and the database.php files and added the necessary credentils. My problem is that the same credentials are working on a raw php file that I have written to test but not on laravel. the laravel project works correctly though on localhost
here is a sample of the .env file code
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=wymtav_food
DB_USERNAME=wymtav_admin
DB_PASSWORD=PasswordNce
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
and here is a snippet of the edited database.php file
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'wymtav_food'),
'username' => env('DB_USERNAME', 'wymtav_admin'),
'password' => env('DB_PASSWORD', 'PasswordNce'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Note that on local environment, the database port was 3309 and I have changed it to 3306 as per the production environment port. What could I be doing wrong?
DB_HOSTvalue is set to127.0.0.1which stands for localhost. Your provider should give you a remote mysql db host. Could this be the issue? - AlexioVay<?php $database ="wymtav_food"; $user ="wymtav_admin"; $password ="PasswordNce"; $port = "3306"; $host = "localhost"; $conn = mysqli_connect($host, $user, $password, $database, $port); if(!$conn){ echo mysqli_error($conn); }- The Only Smart Boy