0

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.

nj167252
  • 139
  • 2
  • 14
  • Does this answer your question? [Laravel: Error \[PDOException\]: Could not Find Driver in PostgreSQL](https://stackoverflow.com/questions/25329302/laravel-error-pdoexception-could-not-find-driver-in-postgresql) – miken32 Jun 12 '23 at 19:39
  • It doesn't explain why ````php artisan tinker```` and migrations can access the database perfectly. In tinker I run ````use App\Sales;```` and ````Sales::limit(10)->get();```` and results are displayed. – nj167252 Jun 13 '23 at 06:13
  • Providing more detail than "500 error" would be helpful to diagnosing the problem. – miken32 Jun 13 '23 at 16:49
  • Where can I go to find more information? – nj167252 Jun 14 '23 at 05:44
  • There are typically two versions of PHP installed on a server. One is for the CLI and another used by the web server for HTTP requests. Is it possible you don't have the PostgreSQL module configured for both? – fubar Jun 14 '23 at 07:10
  • Interesting @fubar if I go to ````/etc/php```` I see two versions of php 8.1 and 8.2. When I type ````php -v```` from the terminal it displays that I am using PHP 8.2.6. Yet on my Laravel error page it shows that the php version is 8.1.20. – nj167252 Jun 14 '23 at 07:17
  • 1
    Yep, get the `phpinfo` output for both the web server and CLI and check whether the PostgreSQL module is loaded i both. – fubar Jun 14 '23 at 07:32
  • @fubar you are an absolute legend. I ran ````apt-get install php8.1-pgsql```` rather than ````apt-get install php-pgsql```` without being version specific and I am in business. – nj167252 Jun 14 '23 at 08:02
  • @fudar if you want to write out the solution I can mark as correct. – nj167252 Jun 14 '23 at 08:12

1 Answers1

1

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.

fubar
  • 16,918
  • 4
  • 37
  • 43
  • I ran ````apt-get install php8.1-pgsql```` rather than ````apt-get install php-pgsql```` without being version specific, and I am in business. – nj167252 Jun 15 '23 at 05:48