This topic is locked

Change connection to another (secondary) database

4/12/2023 3:43:00 PM
PHPRunner General questions
author

Hi. I am having a trouble to get some results from my secondary database table named "Reg".
I am trying to put some query in events "Welcome page->Before display", but getting error all the time.
I have some global variables to fill initialy. Here is my code in the above event:
$myquery = "select RegType from Reg";
$rs2 = DB::Query($myquery);
$data2=$rs2->fetchAssoc();
if($data2)
{
$TypeReg = implode(" ",$data2);
if ($TypeReg=='1')
{
$_SESSION['var_reg']='1';
}
else
{

$_SESSION['var_reg']='0';
}
}
else
{
$_SESSION['var_reg']='0';
}
I suppose I should change connection to secondary database, but I have tried with:
DB::SetConnection("Reg"); = doesn't work
I appreciate any help!

Sergey Kornilov admin 4/12/2023

Make sure that you read the manual in regards to SetConnection function usage. It takes a connection name, name a table name as an argument.
https://xlinesoft.com/phprunner/docs/db_setconnection.htm

502110 4/12/2023

Guys I have solved the problem!
The problem was in name of the connections.
I have renamed connection and used:
DB::SetConnection("MyConnectionName")
Everything works perfect!