简体   繁体   中英

Symfony2: postgres database access denied

I started learning Symfony2 and I wanted to use Doctrine to create table in my postgres database. I installed postgres and followed this steps:

sudo -i -u postgres

I've created user with name: test and type superuser createuser --interactive

createdb test

I created user test with password test

adduser test

And my parameters.yml in symfony2 looks like this:

parameters: database_driver: pdo_pgsql database_host: 127.0.0.1 database_port: null database_name: test database_user: test database_password: test mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: null mailer_password: null Also I have entity like this:

<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
 /**
 * @ORM\Entity
 * @ORM\Table(name="product")
 */
class Product
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=100)
     */
    protected $name;

    /**
     * @ORM\Column(type="decimal", scale=2)
     */
    protected $price;

    /**
     * @ORM\Column(type="text")
     */
    protected $description;
}

Then I typed this commend in terminal:

php app/console doctrine:generate:entities AppBundle

And I got this warning:

[Doctrine\DBAL\Exception\ConnectionException]                                
  An exception occured in driver: SQLSTATE[28000] [1045] Access denied for us  
  er 'test'@'localhost' (using password: YES)                                  


  [Doctrine\DBAL\Driver\PDOException]                                          
  SQLSTATE[28000] [1045] Access denied for user 'test'@'localhost' (using pas  
  sword: YES)                                                                  


  [PDOException]                                                               
  SQLSTATE[28000] [1045] Access denied for user 'test'@'localhost' (using pas  
  sword: YES)  

What can I do to solve this problem?

EDIT:

I realized that I'm connected to mysql database and I don't know why. How can I change this?

One of our developper encountered this issue last week.

Your parameters.yml seems to be good, but if you have the "standard" config.yml, it don't specify the database_driver

#app/config/config.yml
[...]
# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%" # <---- Add this line ;)
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
[...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM