M
M
Maks Burkov2019-04-11 08:40:30
PostgreSQL
Maks Burkov, 2019-04-11 08:40:30

How to configure the connection string to the database?

In my case ..
There is a name for the database inside the schema name. I'm using postgres!
The default schema is 'public' where tables are created when cli-config.php is run.
I can't find how to set the string to the schema I need and not the default 'public' ..
db-config.php:

<?php

return [
        "dbname"=>"dbname",        
        "user"=>"postgres",
        "password"=>"******",
        "host"=>"localhost",
        "driver"=>"pdo_pgsql"
];

cli-config.php:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;


$dbParams = include 'db-config.php';

// Creating database schema according to entities
// Docs reference below
// https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/tools.html
// https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/configuration.html

$config = Setup::createAnnotationMetadataConfiguration(array("../../entities"),true);
$entityManager = EntityManager::create($dbParams, $config);

return ConsoleRunner::createHelperSet($entityManager);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
irishmann, 2019-04-11
@irishmann

You can edit the postgres user so that it works by default in the desired schema:

alter user имя_пользователя set search_path = схема

M
Melkij, 2019-04-11
@melkij

Schemas are an additional level of ordering entities.
Options to choose from: specify the scheme in the names of objects in queries (usually) or change the search_path to the required one.
This is why the schema name is an attribute in the annotation of the table itself, not the connection string.
https://www.doctrine-project.org/projects/doctrine...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question