R
R
RainbowPower2019-01-21 18:56:29
PHP
RainbowPower, 2019-01-21 18:56:29

Can't use multiple RedBeanPHP databases?

Good evening.
I have two databases, it turns out to use them one by one, but it does not come out together.
Here is the request:

Db::getConnection(1);

$new = R::dispense('test');

$new->content = R::isoDateTime();

$result = R::store($new);

echo $result . '<br>';



Db::getConnection(2);

$new = R::dispense('test');

$new->content = R::isoDateTime();

$result = R::store($new);

echo $result . '<br>';

It writes to the first database, but with the second error, if you swap the bases, the opposite is true.
Connect to db:
public static function getConnection($type)
    {
        if($type == '1'){
            Db::getConnectionDataBaseOne();
        }else if($type == '2'){
            Db::getConnectionDataBaseTwo();
        }
    }
 public static function getConnectionDataBaseOne()
    {
        $params = require_once(ROOT . '/config/db_params.php');

        require_once(ROOT . '/include/redBean/rb-postgres.php');


        $dsn_office = "pgsql:host={$params['host_office']};dbname={$params['dbname_office']}";
        R::addDatabase('office', $dsn_office, $params['user_office'], $params['password_office'], false);

        R::selectDatabase('office');

        $out = R::testConnection();

        return $out;
    }

    public static function getConnectionDataBaseTwo()
    {
        $params = require_once(ROOT . '/config/db_params.php');

        require_once(ROOT . '/include/redBean/rb-postgres.php');


        $dsn_record = "pgsql:host={$params['host_record']};dbname={$params['dbname_record']}";
        R::addDatabase('record', $dsn_record, $params['user_record'], $params['password_record'], false);

        R::selectDatabase('record');

        $out = R::testConnection();

        return $out;
    }

mistake:
Fatal error: Uncaught PDOException: Could not connect to database (?). in /var/www/html/include/redBean/rb-postgres.php:1011 Stack trace: #0 /var/www/html/include/redBean/rb-postgres.php(735): RedBeanPHP\Driver\RPDO- >connect() #1 /var/www/html/include/redBean/rb-postgres.php(1035): RedBeanPHP\Driver\RPDO->runQuery('SELECT table_na...', Array) #2 /var/ www/html/include/redBean/rb-postgres.php(1056): RedBeanPHP\Driver\RPDO->GetAll('SELECT table_na...', Array) #3 /var/www/html/include/redBean/rb -postgres.php(4183): RedBeanPHP\Driver\RPDO->GetCol('SELECT table_na...', Array) #4 /var/www/html/include/redBean/rb-postgres.php(6676): RedBeanPHP \Adapter\DBAdapter->getCol('SELECT table_na...') #5 /var/www/html/include/redBean/rb-postgres.php(5857): RedBeanPHP\QueryWriter\PostgreSQL->
Unfortunately, I didn't find the answer myself.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antony Tkachenko, 2019-01-21
@LemonFox

https://redbeanphp.com/manual3_0/index.php?p=/manu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question