how to try a remote connection host gator and if fails connect by localhost

A

Anonymous

Guest
i test codes using remote connection to host gator. but have to each time uncomment to switch it back to connection that would work live on server. how can i use an if else statement to try by remote connection if testing it on my computer or to use local host if running on server?


$conn = mysqli_connect("50.87.155.149", "nadavrock", "xxx", "nadavroc_personal_website");
// $conn = mysqli_connect("localhost", "nadavrock", "xxx", "nadavroc_personal_website");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
 
There isn't one answer.

That's why you are encouraged to do some research so that you can make an educated decision on what might work in your situation; a bonus to doing all this is that if something changes in the future, you will be able to make a good guess at why it no longer works.

PHP cannot make any guarantees to the contents of the $_SERVER variable since it depends on how it has been loaded, what other components are loaded including the server, what changes you have made to any run files and on which operating system you are using as a server.

So follow the link provided and see if there is anything there that might help you out.
 
Back
Top