Laravel 'could not find driver (SQL: insert into…'

只愿长相守 提交于 2019-12-25 04:14:17

问题


I'm trying to set up a development environment after not having done web dev in over a year. I've installed php 7.2.7 on my computer, then installed composer and WAMP.

I'm using php artisan serve to set up a local server. I'm trying to create a new user in my database's 'users' table, using the following code in my web.php (routes) file.

Route::get('/new', function(){
  User::create([
    'password' => Hash::make('anything'),
    'firstname' => 'Nick',
    'lastname' => 'xyz',
    'email' => 'xyz@ph.com',
    'roleflag' => 0
  ]);
});

But am getting the following error:

This seems to be a pretty common error, and I have found help on other stackoverflow/laracasts posts such as:

Laravel: Error [PDOException]: Could not Find Driver in PostgreSQL

and

https://laracasts.com/discuss/channels/general-discussion/cant-connect-to-sql-server-could-not-find-driver

I've thus uncommented the two lines from my php.ini file, changed my .env and config/database.php file to have appropriate settings/connection values, etc. but still receive this error.

Relevant config.php code:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('venturebreeder', 'forge'),
    'username' => env('root', 'forge'),
    'password' => env('', ''),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],

I'm a bit slower at troubleshooting since it has been a while since I've done this -- can anyone see what I'm doing wrong? Help much appreciated.


回答1:


What lines did you uncomment in php.ini file?

Do you have the pdo_mysql extension installed?

Remove the ; from ;extension=pdo_mysql.so and restart your WAMP server

Source: https://stackoverflow.com/a/35240511/6385459



来源:https://stackoverflow.com/questions/51486940/laravel-could-not-find-driver-sql-insert-into

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!