The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Database Connections
#1
Hello,

is there a way to allow users to connect to multiple Databases using the same DB class?

I hope I'd be able to do something like:
Code:
$db1->findAll('TableInDB1');
$db2->findAll('TableInDB2');


Thank you very much
  Reply
#2
Yes.  So if both dbs use the same credentials (as in same username, same host, same password), you can just do 
$db1 = DB::getDB(['db1name']);
$db2 = DB::getDB(['db2name']);

Then use them as you would the regular db.  If you have a different configuration, let me know and we can figure it out.  

Note that this feature is part of 4.4 and I'm not 100% sure if I pushed it out on the latest 4.3 release, so if that doesn't work, just replace users/classes/DB.php with https://pastebin.com/enb0zaGt
  Reply
#3
Thank you for the quick reply!

Same credentials certainly works.

It would be awesome though, if i could allow every user access to a table in another DB using different credentials.
Would that be possible in 4.4?

Thank you very much
  Reply
#4
I'm working on that. Right now, there's a way where you can put the credentials in the init.php, so you can do

$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'db' => 'oe1',
),
'myotherdb' => array(
'host' => '192.168.25.16',
'username' => 'bob',
'password' => 'bobspw',
'db' => 'oe2',
),

And then do $db2 = getDB(['myotherdb','ns']); //ns means new server
But I haven't written the ability to specify credentials on the fly. I'll work on that.
  Reply
#5
Thanks! I really appreciate it.
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)