TimeSocks's avatar

PDOException: could not find driver (for SQLite)

Howdy,

I've just started a fresh Laravel project, looking to approach it from a TDD point of view. With that in mind, I have setup a simple test, and as per the Birdboard series have set phpunit to use an sqlite database for testing in phpunit.xml

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

However, when I run my test, I get an error caused by:

PDOException: could not find driver

Sqlite is installed on my system (I went and got it and installed it) though the executable only works from the folder I extracted it to. How can I get it working with Laravel?

0 likes
11 replies
Vilfago's avatar

config/database.php

'default' => env('DB_CONNECTION', 'sqlite'),
'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],
]

You can set it in the .env file at your root folder, under the name "DB_CONNECTION" and "DB_DATABASE". The second argument is the default value if the first one is not known.

TimeSocks's avatar

@VILFAGO - That's missing the point. Firstly, it's not missing the database file, it's missing the driver for sqlite, period. Secondly, I don't want to use the same database for testing as for development, as per the Birdboard series. I don't want to fill my development database with test data. Hence using a temporary sqlite database for testing, or trying to.

TimeSocks's avatar
TimeSocks
OP
Best Answer
Level 4

I solved it. I had to enable the sqlite PDO driver in my php.ini file.

3 likes
baumgars's avatar

php --ini

I did enalbe die driver, still not working. On Windows command line it works (with enabled sqlite extension) but not on Ubuntu via WSL2 on command line so most likely conflicting PHP versions installed (find the right version of the ini file). So need to clean up the mess in WSL2 by removing all PHP versions and installing the right one or figuring out how enable only one specific version, editing its ini file and installing the correct PHP version of sqlite. Its clearly advanced stuff that can take you long time to figure out.

The only reason i use WSL2 is i can use curl but it is probably easier in the long term to set up a docker image with exactly one PHP version to not have pains for days due to such a dumb "dll hell"

JussiMannisto's avatar

@baumgars Windows and WSL2 are separate operating systems. The PHP in your Windows is in no way connected to the one in WSL. There's no "dll hell" in WSL because Linux binaries don't use DLL files.

All you need to do is install PHP's sqlite3 extension in WSL for whatever PHP version you're using. It's not advanced stuff, it's basic Linux usage.

If you're struggling with Linux while only using it for curl, why don't you just install curl in Windows?

Edit. I just checked: Windows already has curl installed by default.

baumgars's avatar

@JussiMannisto

"The PHP in your Windows is in no way connected to the one in WSL"

Thats what i was saying.

"There's no "dll hell" in WSL because Linux binaries don't use DLL files."

Obviously this was a metaphor. On Linux you have the "so-hell".

"All you need to do is install PHP's sqlite3 extension in WSL for whatever PHP version you're using. It's not advanced stuff, it's basic Linux usage."

I did and for some reason still did not work so there may be a conflict on .ini files. To figure this out is pretty much advanced stuff.

"If you're struggling with Linux while only using it for curl, why don't you just install curl in Windows?"

Because obviously its easier to use curl in Linux than on Windows.

Please do your homework.

JussiMannisto's avatar

@baumgars

Please do your homework.

What homework would that be, exactly? I already know how to install a package on Linux. And never in my career have I had a "conflict" in a php.ini file, whatever that means. Maybe you could explain what your conflict was, and how you got there?

Please or to participate in this conversation.