Error connecting a postegresql bank to Laravel

Asked

Viewed 624 times

0

I’m having a problem using Laravel with postgresql on Linux, when trying to connect with the database it says it does not find the postgresql driver, I have already enabled postgresql in php.ini so:

extension=pgsql.so
extension=pdo_pgsql.so

This is the SQL Query:

$usuario = DB::select('select * from usuario');

The mistake Laravel shows me is this:

"could not find driver (SQL: select * from usuario)"

I already installed the php-postgresql driver, restarted the two apache2, postgresql services, and also restarted Composer.

My distro is the elementary OS (based on Ubuntu 14.04)

Edit: env.:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=minha_db
DB_USERNAME=meu_user 
DB_PASSWORD=minha_senh3

database php.

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

Edit: Thank God I managed to solve, I tried to install the package with the command below and the driver worked:

sudo apt-get install php7.0-pgsql

Before I had installed without specifying the version and it didn’t work:

sudo apt-get install php-pgsql
  • I imagine that by php-postgresql you mean the package php-pgsql? How are you opening the connection with Postgres? One way to test if the connection is actually happening is to enable the parameters log_connections and log_disconnections in postgresql.conf, re-load Postgres and go check the log file. Another way is to put a long Sleep in PHP after creating the connection and see in the bank if it appears in a select * from pg_stat_activity;

  • 1

    You appear to be missing the install driver, php-pgsql: https://www.tutorialspoint.com/postgresql/postgresql_php.htm

  • @nunks.lol I am using the framework pattern. @Miguel installed the driver and in the file pg_hba.conf I did a config something like this: host all 0.0.0.0/0 md5

  • Connection data is already configured in your .env?

  • Yes, I fixed it already, I switched from mysql to pgsql and put the right credentials.

  • Weird... You can edit your post and put your .env (can omit connection data) and file /config/database.php? Just to see how it’s set up on both.

  • @Guh edite e pus la

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.