2

I want to build Laravel + PostgreSQL existing Project.

config.php

 'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL', "pgsql://postgres:123@127.0.0.1:5432/crawler"),
            'host' => env('DB_POSTGRES_HOST', '127.0.0.1'),
            'port' => env('DB_POSTGRES_PORT', '5432'),
            'database' => env('DB_POSTGRES_DATABASE', 'crawler'),
            'username' => env('DB_POSTGRES_USERNAME', 'postgres'),
            'password' => env('DB_POSTGRES_PASSWORD', '123'),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer'
        ],

I tried to migrate the database.

But error occured.

   Illuminate\Database\QueryException  : could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')

  at E:\Task\cookie.crawler.backend.api\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDO\Exception::("could not find driver")
      E:\Task\cookie.crawler.backend.api\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDO\Exception.php:18

  2   Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException))
      E:\Task\cookie.crawler.backend.api\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:44

  Please use the argument -v to see more details.

What's the reason.

I've installed PostgreSQL recently and not familiar with this.

  • What OS are you using. How did you install php? It seems that you don't have postgres driver in your php instalation. You can try to open your php.ini file and see if `extension=pdo_pgsql` or `extension=pgsql` are uncommented (semicolon). – Erik Roznbeker Jun 29 '23 at 08:10
  • Thanks for your help. I use windows10 and already set up extension=pdo_pgsql in php.ini But not working. – Special Man Jun 29 '23 at 08:12
  • I'm sorry I don't have win10 to test it, but you can try to follow some tutorial (e.g. https://w3guy.com/integrate-postgresql-database-xampp-windows/) and write us if you get error in some step. – Erik Roznbeker Jun 29 '23 at 09:44

2 Answers2

0

The error message you are receiving means that you do not have the PostgreSQL driver installed for PHP, and therefore Laravel is unable to connect to the database, resulting in an error.

Check if the PostgreSQL driver is installed :

php -m | grep pdo_pgsql

If not installed:

sudo apt-get install php-pgsql

After installing , restart your web server:

sudo service apache2 restart

If you are using Windows, Download the PostgreSQL driver and place the downloaded file in your PHP installation directory. For example, choose the path

C:\xampp\php\ext.

and

find the following line in the php.ini file: ;extension=php_pgsql.dll and uncomment it by removing the semicolon at the beginning of the line.

0

I just got an answer. Find php.ini in xampp/php folder. add 2 things. extension=pdo_pgsql extension=pgsql If exist, remove ; from the line. It will works well.

  • Please enclose the code you're using on your replies, within 3 "`", i.e.: ``` This is a code block ``` – Lopofsky Jul 02 '23 at 06:55