我使用PHP 7.1.5的MAMP服务器; Symfony Framework 3.4.2,PostgreSQL 10用于新项目。我还使用PostGIS在PostgreSQL中存储具有几何数据类型的空间数据。因此我安装并使用了:" jsor / doctrine-postgis":" ^ 1.5"
以下是我的composer.json的一部分:
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"jsor/doctrine-postgis": "^1.5",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0"
参数.yml:
server_ver: 10.0
database_driver: pdo_pgsql
database_host: localhost
database_port: 5432
database_name: qtqg
database_path: ~
database_user: postgres
database_password: admin
config.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
mapping_types:
_text: string
server_version: %server_ver%
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
path: %database_path%
user: %database_user%
password: %database_password%
persistent: true
charset: UTF8
logging: %kernel.debug%
profiling: %kernel.debug%
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
types:
geography:
class: 'Jsor\Doctrine\PostGIS\Types\GeographyType'
commented: false
geometry:
class: 'Jsor\Doctrine\PostGIS\Types\GeometryType'
commented: false
raster:
class: 'Jsor\Doctrine\PostGIS\Types\RasterType'
commented: false
一切正常,我可以使用cmd生成实体:
php bin/console doctrine:mapping:import --force AppBundle annotation
然后生成CRUD:
php bin/console generate:doctrine:crud AppBundleMonitoringAdminBundle:coquan -n --format=annotation --with-write
Running PHP是PHP 7.1.5,我还检查了C:\ Windows中的php.ini文件,并在MAMP服务器中加载了php.ini。 php -m
命令显示:
PDO
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
我认为数据驱动程序没有任何问题,因为它可以连接并生成实体,CRUD .... 但是在生成CRUD并尝试访问控制器以列出一个实体中的所有项目之后,我得到了错误:
An exception occurred in driver: could not find driver
其中一个错误行是:
AbstractPostgreSQLDriver->convertException('An exception occurred in driver: could not find driver', object(PDOException)) in vendor\doctrine\dbal\lib\Doctrine\DBAL\DBALException.php (line 176)
我尝试了很多方法,包括将mamp更改为xamp,wamp服务器,所有关于如何配置dbal的建议......但错误仍然存在
任何人都可以帮助我!
答案 0 :(得分:1)
问题在于PostgreSQL 10
在vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
内线292更改
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
有关
$version = floatval($this->_conn->getWrappedConnection()->getServerVersion());
if ($version >= 10) {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = \'public\' AND sequencename = '.$this->_conn->quote($sequenceName));
}
else
{
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
}
答案 1 :(得分:0)
我在Windows 10上使用WAMP的Postgres 9.6.4遇到了相同的问题
phpinfo()
将在加载后显示pdo_pgsql
,并且在另一个PHP应用程序中也可以正常工作。 gitbash中的php -m
不会显示pdo_pgsql
最后,我不得不编辑已加载的php.ini,并取消注释这两行
extension=php_pdo_pgsql.dll
extension=php_pgsql.dll
重新启动apache,现在可以使用了!!!!