I started using Illuminate Database for a project, in isolation from the rest of the Laravel framework using composer require illuminate/database with the latest version.
A mistake with the connection configuration triggers the following error message, which doesn't describe the problem at all, and doesn't give any indication as to where the actual issue is:
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in vendor/illuminate/container/Container.php:763
Stack trace:
#0 vendor/illuminate/container/Container.php(644): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 vendor/illuminate/database/Connectors/ConnectionFactory.php(130): Illuminate\Container\Container->make('Illuminate\\Cont...')
#2 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#3 vendor/illuminate/database/Connection.php(964): call_user_func(Object(Closure))
#4 vendor/phpgt/database/src/Query/SqlQuery.php(46): Illuminate\Database\Connection->getPdo()
#5 vendor/phpgt/database/src/Query/SqlQuery.php(17): Gt\Database\Query\SqlQuery- in vendor/illuminate/container/Container.php on line 763
When adding the database connection using Illuminate\Database\Capsule\Manager::addConnection (as described in the Database readme, line 5), I had a typo on the "charset" value. Instead of "utf8", my associative array contained "utf-8".
Further on in my code, I called Illuminate\Database\Connection::getPdo, which causes the above error to be output.
I assume the problem is a dependency issue between internal Laravel/Illuminate packages, so that an exception like "Invalid MySQL configuration" isn't being able to be thrown.
I'm running into the same problem.
@kevinburke do you have the connection settings correct? My problem was resolved due to a typo on the charset. The issue here is really down to the fact that there is no indication of the actual problem through the error that's output. Very difficult to debug a simple problem without knowledge of Laravel's internals.
I don't think so, but I'm not sure how to fix them. I haven't been able to
find documentation for valid Postgres settings, and I can't figure out
what's going wrong.
On Wed, Nov 23, 2016 at 01:50 Greg Bowler [email protected] wrote:
@kevinburke https://github.com/kevinburke do you have the connection
settings correct? My problem was resolved due to a typo on the charset. The
issue here is really down to the fact that there is no indication of the
actual problem through the error that's output. Very difficult to debug a
simple problem without knowledge of Laravel's internals.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/laravel/framework/issues/16502#issuecomment-262471029,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAOSI92thPz74XMebhzVJHVuHoRHLCNJks5rBAxTgaJpZM4K5kUf
.
I see the issue. We can probably issue a fix fairly easy.
Thanks - in the meantime, any idea how to diagnose where I'm going wrong with my config?
(I figured it out by guessing)
Thanks @taylorotwell - I wouldn't mind helping contribute to this one, but I'm struggling to work out where to start. Any advice would be great to help me provide a more meaningful exception here.
Any news on this one? I got the same error using Slim Framework with:
Hi, the solution for me was to properly connect the database, my connection data was wrong, but when connecting correctly to the database, everything just work
I had a similar situation. An environment variable wasn't set correctly so Eloquent was using the wrong credentials to establish the connection. Here is how I overcame the Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable error:
To confirm, the reason this issue comes up is almost definitely because your database connection settings are wrong, but this issue is reporting the lack of understandable error message by Laravel which could easily say "unable to connect to database", but instead gives you a BindingResolutionException.
@g105b That's right. Although, when the exception handler is defined correctly, that's exactly what Eloquent is telling you (unable to connect to database).
I understand, but by default on a fresh install the exception handler is not defined correctly.
Would perhaps be a better option to instead ask for a the "psr logger" rather than "Illuminate exception handler" across the framework.
Any update on this? I've got some devs who are _sure_ that their DB configuration info is correct, but they're still running into this exception with no useful error information.
My workaround for this is, before trying to access the database for the first time through Capsule, to simply wrap a standard PHP PDO connection attempt in a try...catch:
// Test database connection directly using PDO
// $dbParams has your database config
try {
$dbh = new \PDO("{$dbParams['driver']}:host={$dbParams['host']};dbname={$dbParams['database']}", $dbParams['username'], $dbParams['password']);
} catch (\PDOException $e) {
$message = PHP_EOL . "Could not connect to the database '{$dbParams['username']}@{$dbParams['host']}/{$dbParams['database']}'. Please check your database configuration and/or google the exception shown below:" . PHP_EOL;
$message .= "Exception: " . $e->getMessage() . PHP_EOL;
$message .= "Trace: " . $e->getTraceAsString() . PHP_EOL;
die($message);
}
This is fixed in 5.4
Most helpful comment
To confirm, the reason this issue comes up is almost definitely because your database connection settings are wrong, but this issue is reporting the lack of understandable error message by Laravel which could easily say "unable to connect to database", but instead gives you a BindingResolutionException.