执行查询时出现“找不到驱动程序”消息

时间:2019-10-28 07:47:01

标签: laravel ubuntu composer-php

我有一个Laravel项目。直到我将Ubuntu 19.04更新到19.10为止,一切都很好。在Postman上测试API时,出现此错误:

"message": "could not find driver (SQL: select * from `users` where `username` = genesis limit 1)",
"exception": "Illuminate\\Database\\QueryException",
"file": "/home/arkhalis/Repos/laravel/safetrade/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
"line": 664

然后我尝试在终端上运行Composer并获得此输出

PHP Fatal error:  Uncaught Error: Call to undefined function Symfony\Component\Console\Helper\mb_detect_encoding() in /usr/share/php/Symfony/Component/Console/Helper/Helper.php:50
Stack trace:
#0 /usr/share/php/Symfony/Component/Console/Descriptor/TextDescriptor.php(329): Symfony\Component\Console\Helper\Helper::strlen('h')
#1 /usr/share/php/Symfony/Component/Console/Descriptor/TextDescriptor.php(97): Symfony\Component\Console\Descriptor\TextDescriptor->calculateTotalWidthForOptions(Array)
#2 /usr/share/php/Symfony/Component/Console/Descriptor/TextDescriptor.php(197): Symfony\Component\Console\Descriptor\TextDescriptor->describeInputDefinition(Object(Symfony\Component\Console\Input\InputDefinition), Array)
#3 /usr/share/php/Symfony/Component/Console/Descriptor/Descriptor.php(55): Symfony\Component\Console\Descriptor\TextDescriptor->describeApplication(Object(Composer\Console\Application), Array)
#4 /usr/share/php/Symfony/Component/Console/Helper/DescriptorHelper.php(67): Symfony\Component\Console\Descriptor\Descriptor->describ in /usr/share/php/Symfony/Component/Console/Helper/Helper.php on line 50

Fatal error: Uncaught Error: Call to undefined function Symfony\Component\Console\Helper\mb_detect_encoding() in /usr/share/php/Symfony/Component/Console/Helper/Helper.php:50
Stack trace:
#0 /usr/share/php/Symfony/Component/Console/Descriptor/TextDescriptor.php(329): Symfony\Component\Console\Helper\Helper::strlen('h')
#1 /usr/share/php/Symfony/Component/Console/Descriptor/TextDescriptor.php(97): Symfony\Component\Console\Descriptor\TextDescriptor->calculateTotalWidthForOptions(Array)
#2 /usr/share/php/Symfony/Component/Console/Descriptor/TextDescriptor.php(197): Symfony\Component\Console\Descriptor\TextDescriptor->describeInputDefinition(Object(Symfony\Component\Console\Input\InputDefinition), Array)
#3 /usr/share/php/Symfony/Component/Console/Descriptor/Descriptor.php(55): Symfony\Component\Console\Descriptor\TextDescriptor->describeApplication(Object(Composer\Console\Application), Array)
#4 /usr/share/php/Symfony/Component/Console/Helper/DescriptorHelper.php(67): Symfony\Component\Console\Descriptor\Descriptor->describ in /usr/share/php/Symfony/Component/Console/Helper/Helper.php on line 50

我还尝试运行composer update并获得与this question相同的结果并运行sudo apt-get install php-mbstring,但与我在终端上运行composer命令相同的结果。

1 个答案:

答案 0 :(得分:2)

尝试安装Laravel所需的所有扩展。请看看here

如果您使用的是PHP 7.1,则可以尝试运行以下命令:

sudo apt install php7.1 php7.1-fpm php7.1-curl php7.1-mysql php7.1-common php7.1-mbstring php7.1-mcrypt php7.1-xml

或者,如果您使用的是PHP7.2,则可以运行此命令(没有mcrypt,因为它已被删除)

sudo apt install php7.2 php7.2-fpm php7.2-curl php7.2-mysql php7.2-common php7.2-mbstring php7.2-xml

如果遇到错误,则可能没有添加任何PHP存储库。尝试通过OndřejSurý添加此完整的PHP存储库。

sudo add-apt-repository ppa:ondrej/php
sudo apt update

更新

由于您使用的是Ubuntu 19.10(Eoan),所以我听说默认情况下它随PHP 7.3一起提供。因此,也许您可​​以尝试:

sudo apt install php php-fpm php-curl php-mysql php-common php-mbstring php-xml

目前ondrej/php仍未发行19.10的任何PHP软件包(因为Ubuntu 19.10是最近发行的)。作者需要花费一些时间来发布软件包。