简体   繁体   中英

I tried using postgresql on laravel but got could not find driver (SQL: select * from “users” where “id” = 4 limit 1)

Good day fellow Artisans, please I have an issue with PostgreSql, I have an application that I am using MySql and everything is working fine, but I have to use another database PostgresSql, I did the necessary connection and ran php artisan migrate , the migration ran without errors and the tables were created, but when I try to register a new user, I got this error.

I have cleared my cache, route, config, and also view

php artisan config:cache
php artisan route:clear
php artisan view:clear
php artisan cache:clear

Postgres 错误

.env

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=mydatabase
DB_USERNAME=postgres
DB_PASSWORD=mypassword

I am using WAMP , so I have uncommented the pgsql extension in php.ini

;extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
;extension=phpdbg_webhelper

running php -m , it listed pdo_pgsql also

It seems that you enable lack of extension. We also need to enable php_pgsql and php_pdo_pgsql in php.ini because your PHP installation does not support PostgreSQL.

After enabling this extensions, you may not see installed extension in phpinfo . In this case, you should check error log; you may need to install additional libraries.

thank you all for your contributions, but I guess my system was the cause because it seems I did everything right initially, what happened was, After I got that error and I was not able to resolve it then, I switched back to MySql and continued with my task, at the end, I needed to restart my system for system update, after restarting, I said I should give the PostgreSql a shot, I edited my.env back to the configuration above, and also run php artisan config:cache , (which I did before) and the error is gone, I am now using PostgreSql with my laravel application.

My Observations

  1. I need to restart my system after I uncomment pgsql and pdo_pgsql in my php.ini .
  2. I must stop my WAMPSERVER and also my php artisan serve was running, I should have stopped and restarted them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM