Laravel控制器无法连接到PostgreSQL,显示’could not find driver’错误。

huangapple go评论62阅读模式
英文:

Laravel Controllers not connecting to postgres 'could not find driver'

问题

I am using Laravel 10.10 on Debian 10.2 with Postgres 13.11. php artisan tinker works and I can retrieve data this way, I can even migrate to the database. But I cannot get data through the Controllers.

return view('sales', [
    'sales' => Sales::findOrFail(2)
])

results in could not find driver (Connection: pgsql...

I don't think this is a routes issue. When I go to Network and look at the database table connect it says 500 error. I also have sorted my database configuration, since I can migrate. I have also tried numerous remedies that I could find but I've had no success.

This is unique because I can connect to the database through tinker and by running migrations. So I am making a silly mistake somewhere else.

laravel.log output...

[2023-06-14 06:42:42] local.ERROR: could not find driver (Connection: pgsql, SQL: select * from "migrations") {"exception":"[object] (Illuminate\\Database\\QueryException(code: 0): could not find driver (Connection: pgsql, SQL: select * from \"migrations\") at /var/www/html/driptech/vendor/laravel/framework/src/Illuminate/Database/Connection.php:795)
[stacktrace]
英文:

I am using Laravel 10.10 on Debian 10.2 with Postgres 13.11. php artisan tinker works and I can retrieve data this way, I can even migrate to the database. But I cannot get data through the Controllers.

return view('sales', [
    'sales' => Sales::findOrFail(2)
]);

results in could not find driver (Connection: pgsql...

I don't think this is a routes issue. When I go to Network and look at the database table connect it say 500 error. I also have sorted my database configuration, since I can migrate. I have also tried numerous remedies that I could find but I've had no success.

This is unique because I can connect to the database through tinker and by running migrations. So I am making a silly mistake somewhere else.

laravel.log output...

[2023-06-14 06:42:42] local.ERROR: could not find driver (Connection: pgsql, SQL: select * from "migrations") {"exception":"[object] (Illuminate\\Database\\QueryException(code: 0): could not find driver (Connection: pgsql, SQL: select * from \"migrations\") at /var/www/html/driptech/vendor/laravel/framework/src/Illuminate/Database/Connection.php:795)
[stacktrace]

Any assistance would be appreciated.

答案1

得分: 1

通常服务器上会安装两个版本的PHP。一个用于在响应HTTP请求时由Web服务器使用,另一个用于CLI。

有可能您没有为这两个安装都安装或配置PostgreSQL模块吗?

使用phpinfo()函数和php -i命令来检查是否已安装并启用了PostgreSQL。

英文:

Typically there are two versions of PHP installed on a server. One is used by the web server when responding to HTTP requests and the other is for the CLI.

Is it possible that you don't have the PostgreSQL module installed or configured for both installations?

Use the phpinfo() function and php -i command to check if PostgreSQL is installed and enabled.

huangapple
  • 本文由 发表于 2023年6月12日 21:21:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457096.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定