Framework: Database driver not found

Created on 14 Jan 2017  路  10Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.29
  • PHP Version: 7.1
  • Database Driver & Version: postgresql 9.4.5

Description:

Strangly the database driver not found from the webroute, but is working over the console. Guess it is somekind of middleware issue. I am using auth()->user() inside customs middleware, and it seems, the authentication service is not able to find the driver.
It is happening only after the php7.1. upgrade, with php7.0. everything is working seamlessly.

Steps To Reproduce:

Upgrade to php7.1
Use postgres driver as a default database driver (did not tried with mysql to be honest)
Create a custom middleware, and use it, and try to call auth()->user()
You should recieve an error like this:

Next Illuminate\Database\QueryException: could not find driver (SQL: select * from "users" where "users"."id" = 146 limit 1) in ../releases/20170112180801/vendor/laravel/framework/src/Illuminate/Database/Connection.php:770
#0 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Connection.php(726): Illuminate\Database\Connection->runQueryCallback('select * from "...', Array, Object(Closure))
#1 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Connection.php(351): Illuminate\Database\Connection->run('select * from "...', Array, Object(Closure))
#2 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1648): Illuminate\Database\Connection->select('select * from "...', Array, true)
#3 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1634): Illuminate\Database\Query\Builder->runSelect()
#4 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(638): Illuminate\Database\Query\Builder->get(Array)
#5 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(327): Illuminate\Database\Eloquent\Builder->getModels(Array)
#6 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(297): Illuminate\Database\Eloquent\Builder->get(Array)
#7 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(171): Illuminate\Database\Eloquent\Builder->first(Array)
#8 ../releases/20170114080157/bootstrap/cache/compiled.php(1126): Illuminate\Database\Eloquent\Builder->find(327)
#9 ../releases/20170114080157/bootstrap/cache/compiled.php(606): Illuminate\Auth\EloquentUserProvider->retrieveById(327)
#10 ../releases/20170114080157/bootstrap/cache/compiled.php(544): Illuminate\Auth\SessionGuard->user()
#11 ../releases/20170114080157/bootstrap/cache/compiled.php(492): Illuminate\Auth\SessionGuard->check()
#12 ../releases/20170114080157/app/Poker/Helpers.php(51): Illuminate\Auth\AuthManager->__call('check', Array)
#13 ../releases/20170114080157/app/Poker/Helpers.php(57): merUser('check')
#14 ../releases/20170114080157/app/Http/Middleware/IsExternalAuth.php(22): merUser('external')
#15 ../releases/20170114080157/bootstrap/cache/compiled.php(10059): App\Http\Middleware\IsExternalAuth->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#17 ../releases/20170114080157/bootstrap/cache/compiled.php(10044): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#18 ../releases/20170114080157/bootstrap/cache/compiled.php(8346): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#19 ../releases/20170114080157/bootstrap/cache/compiled.php(8337): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#20 ../releases/20170114080157/bootstrap/cache/compiled.php(8328): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#21 ../releases/20170114080157/bootstrap/cache/compiled.php(2575): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#22 ../releases/20170114080157/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#23 ../releases/20170114080157/app/Http/Middleware/XXXMiddleware.php(45): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#24 ../releases/20170114080157/bootstrap/cache/compiled.php(10059): App\Http\Middleware\XXXMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#25 /home/forge/preflopshark.mooo.com/releases/20170112180801/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(3309): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#27 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(10052): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#28 /home/forge/preflopshark.mooo.com/releases/20170112180801/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(13725): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(10052): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#31 /home/forge/preflopshark.mooo.com/releases/20170112180801/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(12131): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#33 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(10052): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 /home/forge/preflopshark.mooo.com/releases/20170112180801/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(13471): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#36 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(10052): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#37 /home/forge/preflopshark.mooo.com/releases/20170112180801/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(13408): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#39 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(10052): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#40 /home/forge/preflopshark.mooo.com/releases/20170112180801/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#41 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(3371): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#42 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(10052): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#43 /home/forge/preflopshark.mooo.com/releases/20170112180801/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#44 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(10037): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#45 /home/forge/preflopshark.mooo.com/releases/20170112180801/bootstrap/cache/compiled.php(2519): Illuminate\Pipeline\Pipeline->then
#46 ../releases/20170112180801/bootstrap/cache/compiled.php(2503): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#47 ../releases/20170112180801/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#48 {main}

All 10 comments

That is not an error, only the stack trace. Please include the error at the end of the slack trace too.

fixed

And you're certain this was working fine on PHP 7.0?

Are you able to downgrade to 7.0 with the same set of dependencies to confirm please?

Yes, I am using forge but I am using mainly postgresql, and not mysql at all. During my routine I accidently upgraded the things to php7.1. Then I tried to fix the error, than I realized everything is working properly (artisan commands, tinker etc...) but when I do try to auth during on the middleware, or route php level, everything is failing. I do use old laravel upgrade (from 5.2), so my kernel.php looks like this

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \App\Http\Middleware\XXXMiddleware::class,
    ];

    /**
     * The application's route middleware.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'authactive' => \App\Http\Middleware\IsActiveAuth::class,
        'authadmin' => \App\Http\Middleware\IsAdminAuth::class,
        'authhud' => \App\Http\Middleware\IsHudAuth::class,
        'authexternal' => \App\Http\Middleware\IsExternalAuth::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
         'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    ];

But the issue is happening in the route.php as well, if I try to use auth()->user() it seems, the authservice is not able to find the default db driver, which is like this:

//from laravel 5.2 I did not changed this....
    'fetch' => PDO::FETCH_CLASS,
    'default' => 'pgsql',
        'pgsql' => [
            'driver'   => 'pgsql',
            'host'     => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),


And, you definitely have installed the pgsql extension on the server?

Do you find any reasoning if I did not install why the console commands are working (using database connection) and why the tinker is working (query the database)
But... I was checking the logs again to show the other services was working, and I found this error, guess this is much more relevant:

[2017-01-14 09:10:01] live.INFO: mesaure : 2017-01-14 09:10:01
[2017-01-14 09:10:01] live.INFO: migrateplayer 1484381401 0 metric_type=gauge
[2017-01-14 09:10:14] live.INFO: process tourney: 1791661013
[2017-01-14 09:10:15] live.INFO: process tourney: 1791661308
[2017-01-14 09:10:16] live.INFO: refreshed user count: 11
[2017-01-14 09:10:16] live.INFO: refresh user                  : 14.268
[2017-01-14 09:10:16] live.INFO: checking leak dropbox files
[2017-01-14 09:10:16] live.ERROR: PDOException: could not find driver in /home/forge/preflopshark.mooo.com/releases/20170114080157/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
Stack trace:
#0 /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(43): PDO->__construct('pgsql:host=loca...', 'forge', 'forge', Array)
#1 /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(116): Doctrine\DBAL\Driver\PDOConnection->__construct('pgsql:host=loca...', 'forge', 'forge', Array)
#2 /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(56): Illuminate\Database\Connectors\Connector->createPdoConnection('pgsql:host=loca...', 'forge', 'forge', Array)
#3 /vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php(36): Illuminate\Database\Connectors\Connector->createConnection('pgsql:host=loca...', Array, Array)
#4 /bootstrap/cache/compiled.php(12026): Illuminate\Database\Connectors\PostgresConnector->connect(Array)
#5 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#6 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(965): call_user_func(Object(Closure))
#7 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(986): Illuminate\Database\Connection->getPdo()
#8 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(423): Illuminate\Database\Connection->getReadPdo()

Looks like the pdo-pgsql extension is missing.

php -m on my system shows:

[PHP Modules]
apc
apcu
bcmath
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
json
libxml
mbstring
openssl
pcntl
pcre
PDO
pdo_pgsql
pgsql
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

Closing since this is not a framework bug.

I Have an issue
{"error":{"message":"could not find driver (SQL: select * from invites where email = [email protected] and invites.deleted_at is null)","status_code":500}}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iivanov2 picture iivanov2  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

shopblocks picture shopblocks  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments