4 Replies Latest reply: Apr 24, 2012 8:54 AM by whatalotofrubbish RSS

    One Database connection for on line and off line - How?

    whatalotofrubbish Community Member

      In the past, my hosting company allowed me to connect using localhost as the host server.

      Now I have to define a different server when on line to when I am off line.

      It is easy to do using different connection scripts like the following one:

      <?php

      # FileName="Connection_php_mysql.htm"

      # Type="MYSQL"

      # HTTP="true"

      # note that the following line is used for on line only

      #$hostname_dummy = "mysql.online.net";

      # Use the following line for local connection

      $hostname_dummy = "localhost";

      $database_dummy = "database";

      $username_dummy = "username";

      $password_dummy = "password";

      $dummyread = mysql_pconnect($hostname_dummyread, $username_dummyread, $password_dummyread) or trigger_error(mysql_error(),E_USER_ERROR);

      ?>

      All that is required is to comment out the line that you don't need, save the file and upload it to the server. When you have done that and need to work off line, just change the commented line and save it again.

      You need to ensure that you have created users in the privileges section of your on line database that match your local users, or you would need commented lines for the users and passwords also.

      My question is : How do you rewrite the connections so that it works like this:

       

      If  the computer is on line, use the following code

           :$hostname_dummy = "mysql.online.net";

      else use this code

           $hostname_dummy = "localhost";

       

      In other words, how do you detect whether you are on or off line?