Laravel '找不到驱动程序(SQL:插入...'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51486940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:55:42  来源:igfitidea点击:

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

mysqldatabaselaravelpdo

提问by Vranvs

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.

我在一年多没有做 web 开发后试图建立一个开发环境。我已经在我的电脑上安装了 php 7.2.7,然后安装了 composer 和 WAMP。

I'm using php artisan serveto 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.

我正在使用php artisan serve来设置本地服务器。我正在尝试在我的 web.php(路由)文件中使用以下代码在我的数据库的“用户”表中创建一个新用户。

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

But am getting the following error:

但我收到以下错误:

enter image description here

在此处输入图片说明

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

这似乎是一个非常常见的错误,我在其他 stackoverflow/laracasts 帖子中找到了帮助,例如:

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

Laravel:错误 [PDOException]:无法在 PostgreSQL 中找到驱动程序

and

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

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.

因此,我取消了 php.ini 文件中的两行注释,将 .env 和 config/database.php 文件更改为具有适当的设置/连接值等,但仍然收到此错误。

Relevant config.php code:

相关的 config.php 代码:

'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.

我的故障排除速度有点慢,因为我已经有一段时间没有这样做了——有人能看出我做错了什么吗?非常感谢帮助。

回答by Dennis

What lines did you uncomment in php.ini file?

你在 php.ini 文件中取消了哪些行的注释?

Do you have the pdo_mysqlextension installed?

你有pdo_mysql安装扩展吗?

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

取出;;extension=pdo_mysql.so并重新启动WAMP服务器

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

来源:https: //stackoverflow.com/a/35240511/6385459