1

I tried to connect PostgreSQL and laravel I can see all data on pgAdmin. But I can't connect the PostgreSQL on laravel project Please help me Thanks

.Env file

DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=gotmold
DB_USERNAME=postgres
DB_PASSWORD=Slack0206!

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class CurlController extends Controller
{
    public function index(){

    }

    public function view(){
        $User = User::get()->count();
        print_r($User);
    }
}

I got this error I already cleared cache

Illuminate\Database\QueryException
could not find driver (SQL: select * from "users")
http://127.0.0.1:8000/view
5
  • Have you tried config:clear too? Commented Mar 11, 2020 at 18:58
  • Thanks for your reply, Yes, i did Commented Mar 11, 2020 at 19:00
  • I would also check if default database connection is overwritten either in Model or in config/database.php. Commented Mar 11, 2020 at 19:00
  • It's a new project, nothing overwritten. tnx Commented Mar 11, 2020 at 19:01
  • I did the above way but my project still not working. Until when I run "php artisan config:clear" on my project. Commented Jul 9, 2020 at 12:00

3 Answers 3

3

I am using Xampp on window 10 Then I enabled the extensions in php.ini again:

extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll

It works well

Sign up to request clarification or add additional context in comments.

Comments

0

Find file php.inc in xampp ex:C:\xampp\php. open file php.inc, find pgsql and delete accents ";" before extension

Comments

0

The solution is very simple because you have an error in configuration files.

  1. .ENV define connection and DB
  2. In your database.php file in config directory you MUST DECLARE the connection in connections array.

Just only copy the mysql connection there and replace with your datas (user, db, password, host )

    'connections' => [
     
             'sqlite' => [
                 'driver'   => 'sqlite',
                 'database' => database_path('database.sqlite'),
                 'prefix'   => '',
             ],
     'mysql' => [
                 'driver'    => 'mysql',
                 'host'      => env('DB_HOST', 'localhost'),
                 'port'      => env('DB_PORT', '3306'),
                 'database'  => env('DB_DATABASE', 'my_db'),
                 'username'  => env('DB_USERNAME', 'my_user'),
                 'password'  => env('DB_PASSWORD', 'my_password'),
                 'charset'   => 'utf8',
                 'collation' => 'utf8_unicode_ci',
                 'prefix'    => '',
                 'strict'    => false,
                 'engine'    => null,
             ],
     'pgsql' => [ REPLACE_HERE_YOUR_DATA]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.