Answer the question
In order to leave comments, you need to log in
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>';
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;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question