PDO 异常在 Laravel 中找不到驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36370074/
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
PDO exception could not find driver in laravel
提问by Sujal Patel
I was trying to execute a migrate command in laravel 5. But it shows a PDOException error. I changed database.php file to the following:
我试图在 Laravel 5 中执行 migrate 命令。但它显示了 PDOException 错误。我将 database.php 文件更改为以下内容:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
]
回答by Md Rashedul Hoque Bhuiyan
For PDOException: could not find driver for MySQL, and if it is Debian based OS,
对于 PDOException:找不到 MySQL 的驱动程序,如果它是基于 Debian 的操作系统,
sudo apt-get -y install php5-mysql
For more information read this post PDO Exception
有关更多信息,请阅读这篇文章PDO Exception
回答by Sujal Patel
If you are looking for simple solution, I had same issue & this worked for me..
如果您正在寻找简单的解决方案,我遇到了同样的问题,这对我有用..
When you run php artisan from terminal, you invoke php5-cli package.
当您从终端运行 php artisan 时,您会调用 php5-cli 包。
To run artisan with XAMPP's php you need to use:
要使用 XAMPP 的 php 运行 artisan,您需要使用:
/opt/lampp/bin/php artisan migrate
/opt/lampp/bin/php 工匠迁移
But make sure your /opt/lampp/etc/php.ini is properly configured to enable pdo_mysql
但请确保您的 /opt/lampp/etc/php.ini 已正确配置以启用 pdo_mysql
回答by Mahendra Sharma
Possible Reason :
可能的原因:
- Check phpinfo() whether pdo installed or not,if not then enabled from php.ini
- 检查 phpinfo() 是否安装了 pdo,如果没有则从 php.ini 启用
Note : PDO driver installed when we install php., php version can also be issue.
注意:我们安装php时安装了PDO驱动,php版本也有问题。
回答by Alexey Mezenin
You should setup your .env
file. If you do not have one, just rename .env.example
to .env
and use it. Edit it like this:
你应该设置你的.env
文件。如果你没有一个,只需重命名.env.example
到.env
并使用它。像这样编辑它:
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
https://laravel.com/docs/5.2/configuration#environment-configuration
https://laravel.com/docs/5.2/configuration#environment-configuration
回答by Usman
This worked for me "sudo apt-get install php5-sqlite".
这对我有用“sudo apt-get install php5-sqlite”。