I wanted to connect a MySQL database to my Laravel application.
I created one using PHPMyAdmin administration tool of MySQL, then I added it in the .env
as whereas the database.php
application files.
I ran the terminal command: php artisan migrate
which gave me the following error:
could not find driver (SQL: select * from information_schema.tables where table_schema = pl_project and table_name = migrations and table_type = 'BASE TABLE')
at C:UsersuDocumentspl_project_testpl_project_testvendorlaravelframeworksrcIlluminateDatabaseConnection.php:760
756▕ // If an exception occurs when attempting to run a query, we'll format the error
757▕ // message to include the bindings with SQL, which will make this exception a
758▕ // lot more helpful to the developer instead of just the database's errors.
759▕ catch (Exception $e) {
➜ 760▕ throw new QueryException(
761▕ $query, $this->prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
1 C:UsersuDocumentspl_project_testpl_project_testvendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70
PDOException::("could not find driver")
2 C:UsersuDocumentspl_project_testpl_project_testvendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70
PDO::__construct()
Here is the .env
excerpt that I edited:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pl_project
DB_USERNAME=root
DB_PASSWORD=
Here is the database.php
excerpt that I edited:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'pl_project'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'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'),
]) : [],
]
Here is the output of the command: php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
fileinfo
filter
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
A couple of notes:
- I did add PHP to my env variables as well as MySQL.
- I did uncomment
extension=pdo_mysql
inphp.ini
.
But none of it changed anything and I still get the same error.
2
Answers
There is no need in editing database.php file as it is using .env for database info. In case this is new project that did not have .env file, try running php artisan config:clear
Have you tried restarting PC after enabling extension? If you are running your project with artisan serve it will not reflect after you change ini file
I also had few similar issues on couple of machines with database, it got solved with commenting ‘url’ => env(‘DATABASE_URL’), line in mysql
Hope some of this helps
From what I can recall, the default XAMPP installation lucks a
php.ini
file in the pathxampp/php/
.It however has
php.ini-development
andphp.ini-production
configuration files in that path. You would normally have to create a duplicate copy of either of those two files depending on your use case and rename the ‘duplicate copy’ tophp.ini
This renamed file would then be considered as the ‘active/default PHP configuration file’.You would then open this new renamed
php.ini
file, uncomment any necessary extension libraries, save and restart your XAMPP web server (Apache).Addendum
You may need to enable/uncomment the extension libraries below for your case.
Addendum 2
A. Enable/uncomment the line below. Change the path to your XAMPP installation path. I.e: