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

Codes here !

Moderators: egami, macek, gesf

Post Reply
nadavrock
New php-forum User
New php-forum User
Posts: 2
Joined: Fri May 08, 2020 9:47 pm

Fri May 08, 2020 9:50 pm

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);
}
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1192
Joined: Mon Feb 22, 2016 5:52 pm

Sat May 09, 2020 4:48 am

So what did you find when looking into the suggestion on this thread?
nadavrock
New php-forum User
New php-forum User
Posts: 2
Joined: Fri May 08, 2020 9:47 pm

Sat May 09, 2020 9:57 am

do you know the answer to my question?
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1192
Joined: Mon Feb 22, 2016 5:52 pm

Sat May 09, 2020 11:45 am

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.
Post Reply