Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:04:08+00:00 2026-06-08T03:04:08+00:00

I am programming a game in PHP and have the following code to connect

  • 0

I am programming a game in PHP and have the following code to connect to a database

//$sqldb=mysql_connect('godaddy.hostedresource.com', 'godaddyUserName', 'godaddyPassword') OR die ('Unable to connect to database! Please try again later.');
$sqldb=mysql_connect('localhost', 'root', 'mypassword') OR die ('Unable to connect to database! Please try again later.');

The trick here is that if I am on the production server I comment out the godaddy database; when I upload the code to the server I then comment out the localhost code instead.

Unfortunately the ineveitable has happened and I uploaded the code with the wrong connection commented out; this led to 24 hours of locked out customers! 🙁

Is there a way to have the code to tell if it is on the localhost server, and if it isn’t it then looks for the godaddy connection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:04:09+00:00Added an answer on June 8, 2026 at 3:04 am

    you can try this to identify if its on live or localhost

    if($_SERVER["SERVER_NAME"] == "localhost" 
        && 
       $_SERVER["SERVER_ADDR"] == "127.0.0.1"){
      // in localhost
      $hostname = "localhost";
      $username = "localuser";
      $password = "localpassword";
    }else{
      // not in localhost
     $hostname = "livehost";
     $username = "liveuser";
     $password = "livepassword";
    }
    

    and fail if couldn’t connect to database but save the error into a file.

    if(!mysql_connect($hostname,$username,$password)){
     file_put_contents("mysql_connect.error",mysql_error(),FILE_APPEND);
     die("Couldn't connect to database");
    }
    

    a suggestion, try not to use mysql_* anymore, switch to PDO or mysqli ..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am programming an online PHP-based fantasy pet simulation game. I am not very
I am relatively new to programming with PHP. I have created a simple Javascript
Cheers, I ran into this chunk of code in Programming Game AI by Example:
I have some project about game programming, which have to use blender with phanthom
For an open-source multiplayer programming game written in Scala that loads players' bot code
I have vast programming knowledge; C++/C#/ActionScript/ASM/PHP..... so learning the language of SilverLight itself isn't
I have started programming a game for the iphone and as all beginners I
I'm new to game programming. And i have a question. I want to have
I am trying to learn the basics of game programming and I have installed
I would like to start getting involved into mobile game programming. I already have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.