This topic is locked

Get host database connected

7/7/2021 1:34:48 PM
PHPRunner General questions
F
fabiofurlan author

How to get the hostname of the database the site is currently connected to at runtime.
In the attached evidence by the name of the property does not bring
img alt

admin 7/7/2021

The site is not "connected" to anything when you are not executing a database operation. Changing the connection will affect the next database-related operation.

You need to explain when, where and why you are changing the database connection.

F
fabiofurlan author 7/7/2021

Hello I'm changing to validate if the connection with the secondary bank will be made and to get the host of this connection and show on the screen which host it is currently connected to

admin 7/7/2021

It makes more sense but still not enough info. How exactly do you validate the second connection? How do you know that it worked or didn't work?

F
fabiofurlan author 7/8/2021

With the command DB::SetConnection, because when it is executed it is observed that the content of the array $currentConnection is updated as shown in the screen already sent

admin 7/8/2021

The question remains. Like I said, DB::SetConnection() doesn't perform the connection, it just specifies what connection to use the next time database operation is performed.

So it is still not clear how exactly you "validate if the connection with the secondary bank will be made"

F
fabiofurlan author 7/15/2021

Hello specifying better, as the screen sent in the opening of the question, how to get the contents of the array $currentConnection property $host?
Because when trying $currentConnection->$host it generates an error and there is content as shown on the screen.

admin 7/15/2021

No, you cannot access it this way.

If you need to access the current database host address you need to create a new server database connection, save the $host variable to the session variable and then access that session variable from other parts of your project.

F
fabiofurlan author 7/21/2021

Hello sorry but I don't understand, a new connection was created and the SetConnection command was used for this connection so that's exactly the point how to get the host to save in some session variable?

admin 7/22/2021

What is the exact code of your new Server Database Connection?

F
fabiofurlan author 7/22/2021

hello, the code that is on the screen sent at the opening of the topic, follows again:
DB::SetConnection('GOLIN_PROTHEUS_TESTE');
//debug this point to obtain $currentConnection->host
DB::SetConnection('');

admin 7/22/2021

Again, SetConnection() doesn't change the connection, it just tells what connection to use the next time. I'm talking about the Server Database Connection. What code do you have there?

F
fabiofurlan author 7/22/2021

hello I don't think I'm clear enough, let's do it like this, forget everything that was said before, after the command DB::SetConnection, during debug it is observed by the variables that the array $currentConnection property property is loaded with the content we want to get to demonstrate on the page but when trying to get in php with the code $currentConnection->host the error "error(s)_during_the_evaluation" is generated, shown in the screen below, it is clearer now
img alt
?

admin 7/23/2021

I don't know how I can be any clearer. You cannot access properties of the $currentConnection object, it is not designed for this purpose.

One more time. If you need to access the current database host address you need to create a new server database connection, save the $host variable in the session variable and then access that session variable from other parts of your project.

Which part of this is not clear?

A
acpan 7/23/2021

Not sure if this is relevant, read this Xlinesoft's blog about SAAS inplementation by switching of DB names. Maybe you can get some idea how to get the DB connection name.

saas-application-design

HJB 7/23/2021

ECLIPSE is a JAVA based IDE (Integrated Development Environment) where among others as well an PHP Add-on can be downloaded from the ECLIPSE eco system to be able to handle PHP code under ECLIPSE. The user reported an "error(s) during the evaluation" message, launched by the ECLIPSE IDE that something is wrong (either on the MSSQL connection or a faulty installation /configuration of the PHP add-on provided by ECLIPSE). PHPRunner has NOTHING to do with any IDE system at all by being a RAD system (Rapid Application Development) to connect much more easier with MSSQL servers to handle PHP code than ECLIPSE does. From this point of view, it is understandable that the forum admin asked several times for the server connection details to be able to somehow assist, yet I fear, the PHP coded areas seen under the user's ECLIPSE IDE are NOT orginating from generated PHP code by PHPRunner, but are only a result of PHP coding under ECLIPSE's PHP Add-On to handle PHP code. So, I think, the problem can only be solved once the ECLIPSE system installed is overhauled by proper checking whether the MSSQL server connection works well and whether or not the ECLIPSE PHP Add-on version in use is the right one, respectively correctly installed and configured. In other words, as long as ECLIPSE system is sending error messages, it is up to the user than to first use all ECLIPSE based debugging tools to learn more about which part of the ECLIPSE system is responsible to cause error messages. Finally, the "localhost" text seen on the screenshots sent make me to understand that a MSSQL installation was done by the ECLIPSE on his local machine by himself. In other words, things are NOT hosted remotely by professional hosting team and so, my assumption that the locally ECLIPSE system installation had not been done in the right manner (no system upgrades, various PHP add-on versions and tons more issues around a proper ECLIPSE IDE installation). Only chance, I see, is that the user is viewing on of the numeorus Youtube video tutorials in regard to MSSQL connection under ECLIPSE and as well the Youtube tutorials on how to install and to configure the PHP Add-on being down loadable form the ECLIPSE IDE eco system) in the aim to somehow narrow down from which area the error message is coming from .