Posted By

jackkeller on 08/17/10


Tagged

mysql php xampp MAMP localhost configphp


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

convergine
mikael12
tux-world


PHP Smart Config File


 / Published in: PHP
 

URL: http://www.mediaextra.net/2010/workflow/tips-on-local-development/

Here's a little trick I started using when working with XAMPP for localhost and keeping things in tune with the live configuration variables such as username and passwords to mysql (or whatever you're writing for).

The example below figures your working on http://website.com and that your local development server uses no password for the database.

  1. if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") {
  2.  
  3.     $l = mysql_connect ("localhost","root","") or die("Error connecting: <br /><br />".mysql_error());
  4.     mysql_select_db("local_db") or die("Error getting db: <br /><br />".mysql_error());
  5.    
  6.     $siteurl = "http://website.dev/"; // WITH TRAILING SLASH!
  7.  
  8.  
  9. } else {
  10.  
  11.     $l = mysql_connect ("localhost","live_database_user","live_password") or die("Error connecting: <br /><br />".mysql_error());
  12.     mysql_select_db("live_db") or die("Error getting db: <br /><br />".mysql_error());
  13.  
  14.     $siteurl = "http://website.com/"; // WITH TRAILING SLASH!
  15. }

Report this snippet  

You need to login to post a comment.