【发布时间】:2016-07-02 01:18:29
【问题描述】:
我们正在使用 postgres 数据库对 Web 应用程序进行逆向工程。我们想使用 symfony 框架重构代码,但是我们在使用数据库时遇到了问题。
目前,我们的项目正在使用 MySQL 数据库,只是对已使用的表使用相同的结构。问题是,现在,我们需要使用postgresql数据库,因为数据量很大,据我们所知,它并没有真正适应MySQL。
我们进行了大量研究,但未能成功在 symfony 项目中创建 postgresql 数据库。
首先,我们尝试应用本教程:http://www.tutodidacte.com/symfony2-utiliser-une-base-de-donnee-postgresql 我们尽可能将其改编为我们的项目。
这是我们的 config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
#Mysql
default:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
#Postgresql
pgsql:
driver: pdo_pgsql
host: localhost
port: 5432
dbname: "%psql_database_name%"
user: root
password: "%psql_database_password%"
charset: UTF8
#mapping_types:
#geometry: string
orm:
default_entity_manager: default
auto_generate_proxy_classes: "%kernel.debug%"
#naming_strategy: doctrine.orm.naming_strategy.underscore
#auto_mapping: true
entity_managers:
default:
connection: default
# lister les Bundles utilisant la connexion par defaut
#mappings:
#monprojetmysqlBundle: ~
#tutoUserBundle: ~
pgsql:
connection: pgsql # connection name for your additional DB
# bundles utilisant la connexion Postgresql
#mappings:
# PostgresqlBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
但是当我们启动这个命令时:php bin/console dictionary:database:create --connection=pgsql 我们得到了这个答案:
[Doctrine\DBAL\Exception\DriverException]
An exception occured in driver: could not find driver
[Doctrine\DBAL\Driver\PDOException]
could not find driver
[PDOException]
could not find driver
doctrine:database:create [--connection [CONNECTION]] [--if-not-exists] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
好像我们没有模块 pdo_pgsql 所以我们搜索了如何安装它。
为此,我们应用了此 github 页面上提出的脚本:https://gist.github.com/doole/8651341#file-install_psql_php-sh
我们将 postgres.app 的版本更改为 9.5。
经过几次尝试,我们终于成功地将 pdo_pgsql 放在 php -m 的结果上。
但是要知道,当我们启动命令时,我们会得到这个答案:php bin/console dictionary:database:create --connection=pgsql
PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module
Module compiled with module API=20131226
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: pgsql: Unable to initialize module
Module compiled with module API=20131226
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
[Doctrine\DBAL\Exception\DriverException]
An exception occured in driver: could not find driver
[Doctrine\DBAL\Driver\PDOException]
could not find driver
[PDOException]
could not find driver
doctrine:database:create [--connection [CONNECTION]] [--if-not-exists] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
我们试图这样做:Install PHP with Postgresql on MAC using homebrew
但它没有改变任何东西。现在,当我们启动命令 php bin/console dictionary:database:create --connection=pgsql 时,我们对 pdo_pgsql 和 pgsql 有 5 个 PHP WARNING
我们也看到了这个:
How to change a database to postgresql with Symfony 2.0? 和这个:How to create 2 connections (mysql and postgresql) with Doctrine2 in Symfony2 但它并没有真正帮助,因为第一个涉及 debian,我们正在开发 OS X El Capitan,第二个并没有比上一个教程提供更多信息。
最后,我们唯一的希望是有人可以帮助我们...
提前谢谢你。
【问题讨论】:
-
WARNING for pdo_pgsql说什么?您是否确认您已正确安装 pdo-pgsql 模块(通过查看phpinfo()输出 - 请注意 CLI 和服务器的 php-config 可能不同)? -
PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module Module compiled with module API=20131226 PHP compiled with module API=20121212 These options need to match in Unknown on line 0 PHP Warning: PHP Startup: pgsql: Unable to initialize module Module compiled with module API=20131226 PHP compiled with module API=20121212 These options need to match in Unknown on line 0 -
这仍然是相同的警告,但我们有 5 次。我发现使用我使用的所有命令,我重新安装了 php,现在我有 2 个 php.ini。我将尝试完全删除所有内容并使用
brew install php56 --with-postgresql重新安装 php -
成功了。我删除了每个 php 文件并用 brew 重新安装它,现在它可以工作了。我会在白天更具体。谢谢你的命运
-
很高兴你能弄明白!
标签: php mysql postgresql symfony doctrine-orm