php Laravel:PDOException:找不到驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42557693/
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
Laravel: PDOException: could not find driver
提问by artus90
I am developing a website on a server I only have access to MySQL and FTP, so all commands I run are through the b374k php shell . I am experiencing a Laravel problem with SQL driver. I tried switching to file-hosted SQLite (in database/database.sqlite), but the thrown exception is the same as when using MySQL. The input & output of the console is as follows:
我正在服务器上开发一个网站,我只能访问 MySQL 和 FTP,所以我运行的所有命令都是通过 b374k php shell 。我遇到了 SQL 驱动程序的 Laravel 问题。我尝试切换到文件托管的 SQLite(在 database/database.sqlite 中),但抛出的异常与使用 MySQL 时相同。控制台的输入输出如下:
php artisan migrate:refresh --seed
[Illuminate\Database\QueryException]
could not find driver (SQL: select * from sqlite_master where type = 'table ' and name = migrations)
[Doctrine\DBAL\Driver\PDOException]
could not find driver
[PDOException]
could not find driver
The Apache extensions installed on the server are:
服务器上安装的 Apache 扩展是:
/etc/php/5.6/apache2/conf.d/10-mysqlnd.ini,
/etc/php/5.6/apache2/conf.d/10-opcache.ini,
/etc/php/5.6/apache2/conf.d/10-pdo.ini,
/etc/php/5.6/apache2/conf.d/15-xml.ini,
/etc/php/5.6/apache2/conf.d/20-calendar.ini,
/etc/php/5.6/apache2/conf.d/20-ctype.ini,
/etc/php/5.6/apache2/conf.d/20-curl.ini,
/etc/php/5.6/apache2/conf.d/20-dom.ini,
/etc/php/5.6/apache2/conf.d/20-exif.ini,
/etc/php/5.6/apache2/conf.d/20-fileinfo.ini,
/etc/php/5.6/apache2/conf.d/20-ftp.ini, /etc/php/5.6/apache2/conf.d/20-gd.ini,
/etc/php/5.6/apache2/conf.d/20-gettext.ini,
/etc/php/5.6/apache2/conf.d/20-iconv.ini,
/etc/php/5.6/apache2/conf.d/20-json.ini,
/etc/php/5.6/apache2/conf.d/20-mbstring.ini,
/etc/php/5.6/apache2/conf.d/20-mcrypt.ini,
/etc/php/5.6/apache2/conf.d/20-mysql.ini,
/etc/php/5.6/apache2/conf.d/20-mysqli.ini,
/etc/php/5.6/apache2/conf.d/20-pdo_mysql.ini,
/etc/php/5.6/apache2/conf.d/20-phar.ini,
/etc/php/5.6/apache2/conf.d/20-posix.ini,
/etc/php/5.6/apache2/conf.d/20-readline.ini,
/etc/php/5.6/apache2/conf.d/20-shmop.ini,
/etc/php/5.6/apache2/conf.d/20-simplexml.ini,
/etc/php/5.6/apache2/conf.d/20-sockets.ini,
/etc/php/5.6/apache2/conf.d/20-sysvmsg.ini,
/etc/php/5.6/apache2/conf.d/20-sysvsem.ini,
/etc/php/5.6/apache2/conf.d/20-sysvshm.ini,
/etc/php/5.6/apache2/conf.d/20-tokenizer.ini,
/etc/php/5.6/apache2/conf.d/20-wddx.ini,
/etc/php/5.6/apache2/conf.d/20-xmlreader.ini,
/etc/php/5.6/apache2/conf.d/20-xmlwriter.ini,
/etc/php/5.6/apache2/conf.d/20-xsl.ini,
/etc/php/5.6/apache2/conf.d/20-zip.ini
What can be the problem and how can I fix it? (I don't have access to root bash)
可能是什么问题,我该如何解决?(我无权访问 root bash)
回答by Nibb
If you can, run :
如果可以,请运行:
composer update
composer require doctrine/dbal
It looks like you have a missing dependency
看起来您缺少依赖项
Edit:
编辑:
You might need to comment out the following in your php.ini file.
您可能需要在 php.ini 文件中注释掉以下内容。
;extension=pdo_mysql.so
Taken from this post: Laravel 5 PDOException Could Not Find Driver. I think I had to do something exactly like this when setting up laravel on digital ocean.
摘自这篇文章: Laravel 5 PDOException 无法找到驱动程序。我想在数字海洋上设置 Laravel 时,我必须做类似的事情。
回答by abhishek subedi
Your database driver is missing. To solve the probelm
您的数据库驱动程序丢失。解决问题
First install the driver
首先安装驱动
For ubuntu: For mysql database.
对于 ubuntu:对于 mysql 数据库。
sudo apt-get install php5.6-mysql/php7.2-mysql
You also can search for other database systems.
您还可以搜索其他数据库系统。
You also can search for the driver:
您也可以搜索驱动程序:
sudo apt-cache search drivername
Then Run the cmd php artisan migrate
然后运行cmd php artisan migrate
回答by Mubashar Abbas
I got the same error when running my test suite. It was working before but it stopped working after I upgraded php. So I did
运行我的测试套件时遇到了同样的错误。它之前可以工作,但在我升级 php 后它停止工作。所以我做了
sudo apt-get install php-sqlite3
and it worked.
它奏效了。
回答by Stan Smulders
Even simpler in Ubuntu (18.04)
在 Ubuntu (18.04) 中更简单
apt install php-mysql
apt install php-mysql
Done. No need to edit any .ini
files.
完毕。无需编辑任何.ini
文件。
Happy coding!
快乐编码!
回答by Nadim Tareq
First check php -m
.If you don't see mysql driver install mysql sudo apt-cache search php-mysql
Your results will be similar to:
首先检查php -m
. 如果没有看到 mysql driver install mysqlsudo apt-cache search php-mysql
你的结果会类似于:
php-mysql - MySQL module for PHP [default]
install php- mysql Driver
安装php-mysql驱动
sudo apt-get install php7.1-mysql
回答by Prodigy
You are probably missing sqlite or the specific DB driver you are trying to migrate.
您可能缺少 sqlite 或您尝试迁移的特定数据库驱动程序。
Install the DB driver and you'd be fine. You don't necessarily need to edit your php.ini file (it's one way to fix it too though).
安装数据库驱动程序,你会没事的。您不一定需要编辑您的 php.ini 文件(尽管这也是修复它的一种方法)。
For sqlite do --> sudo apt-get install php-sqlite3
Then php artisan migrate
对于 sqlite 做 -->sudo apt-get install php-sqlite3
然后php artisan migrate
NB: I assume you have PHP and MySql already installed
注意:我假设您已经安装了 PHP 和 MySql
回答by Radhe Shyam sharma
Solution 1:
解决方案1:
1. php -v
Output:PHP 7.3.11-1+ubuntu16.04.1+deb.sury.org+1 (cli)
输出:PHP 7.3.11-1+ubuntu16.04.1+deb.sury.org+1 (cli)
2. sudo apt-get install php7.3-mysql
Solution 2:
解决方案2:
Check your DB credentials like DB Name, DB User, DB Password
检查您的数据库凭据,如数据库名称、数据库用户、数据库密码
回答by Ian Nato
I had a similar issue in Ubuntu 16.04 and what help me was that i installed php-mysql for php 7.2. I would recommend you run the following command if you have php 7.2 or install php mysql depending on your version of PHP. Make sure that you have installed the DBAL packege
我在 Ubuntu 16.04 中遇到了类似的问题,对我有帮助的是我为 php 7.2 安装了 php-mysql。如果您有 php 7.2 或根据您的 PHP 版本安装 php mysql,我建议您运行以下命令。确保您已安装 DBAL 包
apt-get install php7.2-mysql
systemctl restart apache2
回答by Vrushal Raut
In my case I'm using Ubuntu so I found that my system is not installed php-sqlite3, after installation its got fixed.
就我而言,我使用的是 Ubuntu,所以我发现我的系统没有安装 php-sqlite3,安装后它得到了修复。
sudo apt-get install php7.2-sqlite3
sudo apt-get install php7.2-sqlite3
回答by Chetam Okafor
I had the same issue, and I uncomment extension=pdo_sqlite
and ran the migration
and everything worked fine.
我有同样的问题,我取消注释extension=pdo_sqlite
并运行migration
,一切正常。