0

我使用 MAMP 服务器和 PHP 7.1.5;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

正在运行的 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 的所有建议……但错误仍然存​​在

谁能帮帮我!

4

2 回答 2

1

我在 Windows 10 上使用 WAMP 的 postgres 9.6.4 遇到了同样的问题

phpinfo()将显示pdo_pgsql为已加载,并且在另一个 PHP 应用程序中运行良好。 php -m来自 gitbash 不会显示pdo_pgsql

最后,我不得不编辑加载的 php.ini 并取消注释这两行

extension=php_pdo_pgsql.dll
extension=php_pgsql.dll

重新启动apache,现在它可以工作了!!!!

于 2018-10-26T19:31:41.843 回答
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));
}
于 2017-12-26T16:01:39.093 回答