This topic is locked

$conn object within a SAAS environment

9/23/2021 12:13:53 AM
PHPRunner General questions
R
Robert author

Good Evening,

We have recently transformed our legacy phprunner application to a saas infrastructure following the steps in the following article:

https://xlinesoft.com/blog/2019/10/03/saas-application-design/

Within the application generated code, everything is working well. However, we had a lot of custom queries in events and external function packages that we had created.
Most of these queries referenced the $conn global object in order to establish connection to the Database.

For example:

//////////////////////
global $conn;
$sql = "SELECT * FROM table where (Session='$_SESSION[Session]')";
$result = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($result))
{
$field = $row["field"];
}
/////////////////////////

We have noticed that since changing to SAAS, the $conn object now references the primary saas database with user information and not the second connection that is established to the main database with all the data.

Tables and views in the main Database do not seem to be available using the $conn connection.

My question is, what global variable is available in the system to reference the secondary connection to the main Database? $connx?

I hope I have correctly illustrated.

Thank you

admin 9/23/2021

You should not be using global $conn; or mysqli functions. Simply use the recommended Database API and this issue will be taken care of automatically.

R
Robert author 9/23/2021

Please understand that this is an application that we have been building since phpRunner 8.1. Also, I am not sure that the Database APIs work outside of the php runner environment, i.e., in custom function packages. We have hundreds of thousands of lines of code in our libraries.

My question is: Is there a global connection object for the secondary connection?

admin 9/23/2021

I understand this is an old app. But, there is no global object that you can use to reference a secondary connection.

Database API and other APIs will work in external files as long as you include dbcommon.php file. More info in the manual