PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] Laravel 5 with Postgres SQL

 February 10, 2022     laravel, laravel-5, pdo, php, postgresql     No comments   

Issue

I’m working on Laravel 5 with postgres as database. I’ve configured postgres 9.4 and pgAdmin III and these are working normally. When I try to run migrate it is giving me error:

[PDOException]
could not find driver

This is my database.php

'default' => 'pgsql',

'pgsql' => [            'driver'   => 'pgsql',          
                        'host'     => '127.0.0.1',          
                        'database' => 'fms',            
                        'username' => 'postgres',           
                        'password' => 'root',           
                        'charset'  => 'utf8',           
                        'prefix'   => '',           
                        'schema'   => 'public',         ],

Initially I though, it was due to configuration of postgres on windows 7 but I tried with plain php it works perfect

<?php
   $host        = "host=127.0.0.1";
   $port        = "port=5432";
   $dbname      = "dbname=fms";

   $db = pg_connect( "$host $port $dbname user=postgres password=root"  );
   if(!$db){
      echo "Error : Unable to open database\n";
   } else {
      echo "Opened database successfully\n";
   }
?>

I’ve enabled php_pgsql and php_pdo_sql in wamp as well. I’m not sure how to fix this on laravel 5.


Solution

As you said you already choosed Default Database as Postgres SQL

'default' => 'pgsql',

It is a must that you need to uncomment the pdo and postgres shared object in your php configuration settings (php.ini)

i.e., You need to uncomment the following lines in your php.ini

extension=pdo_pgsql.so
extension=pgsql.so

Note :

Don't forget to stop and start your apache after doing this changes (or php-fpm if using that instead).



Answered By - Sulthan Allaudeen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing