Siamo retroingegnerizzazione di un'applicazione Web che utilizza un database Postgres. Vogliamo rifattorizzare il codice usando il framework symfony ma stiamo affrontando un problema per utilizzare il database con esso.Utilizzare un database postgres con symfony3
Per il momento il nostro progetto sta lavorando con un database MySQL usando solo la stessa struttura per le tabelle utilizzate. Il problema è che, ora, abbiamo bisogno di usare il database postgresql perché ci sono molti dati e non è adattato a MySQL per quanto ne sappiamo.
Abbiamo fatto molte ricerche ma non siamo riusciti a creare un database postgresql nel progetto symfony.
Per prima cosa, abbiamo provato ad applicare questo tutorial: http://www.tutodidacte.com/symfony2-utiliser-une-base-de-donnee-postgresql abbiamo adattato il più possibile il nostro progetto. Ecco la nostra 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 }
ma quando abbiamo lanciato questo comando: php bin/console dottrina: database: creare --connection = pgsql abbiamo avuto questa risposta:
[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>
Sembra che non abbiamo il modulo pdo_pgsql così abbiamo cercato come installarlo.
Per farlo, abbiamo applicato lo script proposto su questa pagina github: https://gist.github.com/doole/8651341#file-install_psql_php-sh
Abbiamo cambiato la versione di postgres.app in 9.5. Dopo alcuni tentativi, siamo finalmente riusciti ad avere pdo_pgsql sul risultato di php -m.
Ma sapere, noi abbiamo questa risposta quando lanciamo il comando: php bin/console dottrina: database: creare --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>
Abbiamo cercato di fare questo: Install PHP with Postgresql on MAC using homebrew ma didn non cambiare nulla Ora abbiamo 5 PHP avvertimento per pdo_pgsql e pgsql quando lanciamo il comando php bin/console dottrina: database: creare --connection = pgsql
Abbiamo anche visto questo: How to change a database to postgresql with Symfony 2.0? e questo: How to create 2 connections (mysql and postgresql) with Doctrine2 in Symfony2 ma non è stato di grande aiuto perché il primo riguarda debian e stiamo lavorando su OS X El Capitan e il secondo non dice più del tutorial precedente.
Infine, l'unica speranza che abbiamo è che qualcuno possa aiutarci ... Grazie in anticipo.
Cosa dice "ATTENZIONE per pdo_pgsql"? Hai verificato di aver correttamente installato il modulo pdo-pgsql (osservando l'output di 'phpinfo()' - sii consapevole del fatto che php-config potrebbe differire per CLI e Server)? – fateddy
'PHP Warning: PHP Startup: pdo_pgsql: impossibile inizializzare il modulo modulo compilato con il modulo API = 20.131.226 PHP compilato con il modulo API = 20121212 Queste opzioni devono corrispondere in Unknown on line 0 PHP Warning: PHP Startup: pgsql : Impossibile inizializzare il modulo Modulo compilato con API modulo = 20131226 PHP compilato con modulo API = 20121212 Queste opzioni devono corrispondere a in Unknown sulla linea 0' – MarcoD
Questo è sempre lo stesso avviso ma lo abbiamo 5 volte. Ho trovato che con tutto il comando che ho usato, reinstallo php e ora ho 2 php.ini. Proverò a rimuovere tutto completamente e reinstallare php con 'brew install php56 --with-postgresql' – MarcoD