php Artisan 迁移找不到驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46745365/
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-08-26 03:15:11  来源:igfitidea点击:

Artisan migrate could not find driver

phplaravel

提问by Bomber

I am trying to install Laravel. I have installed Xampp, but when I try to setup my database using php artisan migrateI get the error:

我正在尝试安装 Laravel。我已经安装了Xampp,但是当我尝试使用设置我的数据库时php artisan migrate出现错误:

[Illuminate\Database\QueryException] could not find driver (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations) [PDOException] could not find driver

[Illuminate\Database\QueryException] 找不到驱动程序 (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations) [PDOException] 找不到驱动程序

config/database.phpfile has the relevant connections:

config/database.php文件有相关的连接:

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
    ],

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

    'pgsql' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        'schema' => 'public',
        'sslmode' => 'prefer',
    ],

    'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '1433'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
    ],

],

Any ideas?

有任何想法吗?

回答by Krishna Kant Chourasiya

In your php.ini configuration file simply uncomment the extension:

在您的 php.ini 配置文件中,只需取消对扩展名的注释:

;extension=php_pdo_mysql.dll

(You can find your php.inifile in the php folder where your stack server is installed.)

(您可以在安装堆栈服务器的 php 文件夹中找到您的php.ini文件。)

If you're on Windowsmake it: extension=php_pdo_mysql.dll

如果您使用的是Windows,请执行以下操作:extension=php_pdo_mysql.dll

If you're on Linuxmake it: extension=pdo_mysql.so

如果您使用的是Linux,请执行以下操作:extension=pdo_mysql.so

And do a quick server restart.

并快速重启服务器。

If this isn't working for you, you may need to install pdo_mysqlextension into your php library.

如果这对您不起作用,您可能需要将pdo_mysql扩展安装到您的 php 库中。

回答by Hiren Spaculus

We have solved the same error by following the below steps.

我们已按照以下步骤解决了相同的错误。

linux command for this type of error occurred then, first of all, check your php.ini file

linux命令出现这种类型的错误然后,首先,检查你的php.ini文件

If your php.ini file exists then in configuration file simply uncomment the extension:

;extension=php_pdo_mysql.dll 

Else follow below steps

step1:php -v

step2: Install php mysql extension

php 7.0 sudo apt-get install php7.0-mysql

php 7.1 sudo apt-get install php7.1-mysql

php 7.2 sudo apt-get install php7.2-mysql

php 7.3 sudo apt-get install php7.3-mysql

step3: service apache2 restart

step4: php artisan migrate

回答by Mazino S Ukah

I know this is a little late, nevertheless i'm answering this for anyone still experiencing this issue on windows (USING XAMPP).

我知道这有点晚了,但是我正在为仍然在 Windows 上遇到此问题的任何人回答这个问题(使用 XAMPP)。

Step 1. Verify that there is a mismatch in your PHP version. To do this, open routes/web.php and create a simple route to return the php information like so:

步骤 1. 验证您的 PHP 版本是否不匹配。为此,打开 routes/web.php 并创建一个简单的路由来返回 php 信息,如下所示:

Route::get('/', function() {
   return response()->json([
    'stuff' => phpinfo()
   ]);
})

phpinfo

php信息

and compare this with output from your command line

enter image description here

在此处输入图片说明

As we can see, in my case there is a mismatch, this usually happens if you have multiple versions of php installed.

Step 2. Add the php version being used by your xampp to your system path enter image description here

步骤 2. 将您的 xampp 使用的 php 版本添加到您的系统路径 在此处输入图片说明

Step 3. Verify that you have the extension enabled in your php.ini file. NB. Make sure you are editing the php.ini file that is shown under the 'loaded configuration file' entry in the results of phpinfo() command. enter image description here

步骤 3. 验证您在 php.ini 文件中启用了扩展。注意。确保您正在编辑 phpinfo() 命令结果中“加载的配置文件”条目下显示的 php.ini 文件。 在此处输入图片说明

回答by Phuc Le

I am a Windows and XAMPP user. What works for me is adding extension=php_pdo_mysql.dllin both php.iniof XAMPP and php.iniin C:\php\php.ini.

我是 Windows 和 XAMPP 用户。什么工作对我来说是增加extension=php_pdo_mysql.dll两个php.ini的XAMPP和php.iniC:\php\php.ini

Run this command in your cmd to know where your config file is

在你的 cmd 中运行这个命令来知道你的配置文件在哪里

php -i | find /i "Configuration File

php -i | find /i "Configuration File

回答by Ho360Code.dev

If you are matching with sqlite database:
In your phpfolder open php.inifile, go to:

如果您匹配sqlite数据库:
在您的php文件夹中打开php.ini文件,转到:

;extension=pdo_sqlite

Just remove the semicolon and it will work.

只需删除分号,它就会起作用。

回答by Kevin Montalvo

In Windows and PHP 7.4.5 go to php.ini and uncomment this line

在 Windows 和 PHP 7.4.5 中,转到 php.ini 并取消注释此行

extension=pdo_mysql

回答by lwin moe hein

If you are on linux systems please try running sudo php artisan migrateAs for me,sometimes database operations need to run with sudo in laravel.

如果你在 linux 系统上请尝试运行sudo php artisan migrate对我来说,有时数据库操作需要在 laravel 中使用 sudo 运行。

回答by rajhem

转到 .env 文件并更改以下内容
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=shreemad
DB_USERNAME=root
DB_PASSWORD=

Change the DB_PASSWORD field to

将 DB_PASSWORD 字段更改为

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=shreemad
DB_USERNAME=root
DB_PASSWORD=" "

In my case it works

在我的情况下它有效

NOTE: If your password in mysql is null

注意:如果您在 mysql 中的密码为空

回答by baradhili

whilst sometimes you might have multiple php versions, you might also have a held-back version of php-mysql.. do a sudo dpkg -l | grep mysql | grep php and compare what you get from php -v

虽然有时您可能有多个 php 版本,但您也可能有一个 php-mysql 的保留版本.. 执行 sudo dpkg -l | grep mysql | grep php 并比较你从 php -v 得到的结果