The config files changed as of this commit https://github.com/laravel/laravel/pull/3200/files Maybe there's the error located. Try to update your Laravel install.
Jan 3, 2015
17
Level 1
PDO connection refused with laravel, but not with $con = new PDO()
I've configured mysql for my laravel 5.0-dev project like so:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST') ?: 'localhost',
'database' => env('DB_DATABASE') ?: 'homestead',
'username' => env('DB_USERNAME') ?: 'homestead',
'password' => env('DB_PASSWORD') ?: 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
However, I get connection refused ('PDOException' with message 'SQLSTATE[HY000] [2002]') whenever I try to interact with the database using either php artisan, or the laravel app itself.
The weird thing is, when I run the code below, the connection doesn't get refused.
<?php
$dsn = 'mysql:dbname=homestead;host=localhost';
$user = 'homestead';
$password = 'secret';
try
{
$dbh = new PDO($dsn, $user, $password);
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
I've been googling for 3 hours now and I haven't found a single solution which actually works. So any help is greatly appreciated.
Level 11
Adding the port should resolve your issue
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST') ?: 'localhost',
'port' => '33060',
'database' => env('DB_DATABASE') ?: 'forge',
'username' => env('DB_USERNAME') ?: 'forge',
'password' => env('DB_PASSWORD') ?: '',
2 likes
Please or to participate in this conversation.