我正在使用以postgres为数据库的Laravel 5.我已经配置了postgres 9.4和pgAdmin III,它们都可以正常工作.当我尝试运行迁移时,它给我错误:
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] 找不到驱动程序
[PDOException] could not find driver
这是我的database.php
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', ],虽然我最初是由于Windows 7上的postgres配置,但是我尝试使用纯PHP使其完美运行
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"; } ?>我还启用了 php_pgsql 和 php_pdo_sql .我不确定如何在laravel 5上解决此问题.
I’ve enabled php_pgsql and php_pdo_sql in wamp as well. I’m not sure how to fix this on laravel 5.
推荐答案正如您所说,您已经选择了Default Database作为Postgres SQL
As you said you already choosed Default Database as Postgres SQL
'default' => 'pgsql',这是必须取消对php配置设置(php.ini)
It is a must that you need to uncomment the pdo and postgres shared object in your php configuration settings (php.ini)
即,您需要在php.ini中取消注释以下行
i.e., You need to uncomment the following lines in your php.ini
extension=pdo_pgsql.so extension=pgsql.so注意:
做完这些更改后,别忘了停止并启动apache(或者使用php-fpm代替).
Don't forget to stop and start your apache after doing this changes (or php-fpm if using that instead).
更多推荐
Laravel 5与Postgres SQL
发布评论