Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query a table in a schema in symfony2 via doctrine?

My database is postgreSQL. I've set my parameters as below:

parameters:
    database_driver: pdo_pgsql
    database_host: 127.0.0.1
    database_port: null
    database_name: sandbox
    database_user: postgres
    database_password: postgres
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt

The problem is that I don't know how to query the existing tables in PostgreSQL. I have no problem with MySQL, but in PostgreSQL I don't actually know what to do.

EDIT:

# app/config/parameters.yml
parameters:
database_driver: pdo_mysql
database_host: localhost
database_name: test_project
database_user: root
database_password: password

And then I create entities to work with my data.

EDIT2:


Tables are already created in postgreSQL. The connection part is done. I've done it successfully. What I want to do now is to create entities based on existing tables. I think now it's much more clear and no one is on the dark side. ;-)

like image 723
Alireza Avatar asked Nov 01 '22 00:11

Alireza


1 Answers

The setup for Postgresql and MySQL are very similar. You do need to make a change outside of the Symfony2 php files to be able to use Postgresql with PHP. In the php.ini file, make sure you enable the extension for pgsql. This needs to be enabled so you can use the database_driver pdo_pgsql

Php.ini file /etc/php5/apache2/php.ini, add:

 extension=pdo.so
 extension=php_pdo_pgsql.so

After this, test that you can either connect to your existing database or create a new database. use schema create or validate depending on your situation and post any errors you receive.

like image 96
George Avatar answered Nov 09 '22 12:11

George