title: PHP: define constants outside a class or in the constructor?
body: <p>i'm new to classes and oo.
  I was looking for a basic MySQL class to start with, and i found "A Simple MySQL Class" by Matthew Saragusa.</p>
  
  <p>These are the first lines:</p>
  
  <pre><code>define('SIMPLE_DB_SERVER', 'mysqlserver.net');
  define('SIMPLE_DB_NAME', 'mydbname');
  define('SIMPLE_DB_USERNAME', 'myusername');
  define('SIMPLE_DB_PASSWORD', 'mypassword');
  class ASimpleMySQLDB {
      public function __construct($server, $database, $username, $password){
  
          $this-&gt;conn = mysql_connect($server, $username, $password);
          $this-&gt;db = mysql_select_db($database,$this-&gt;conn);
      }
  [...]
  </code></pre>
  
  <p>I wonder if there is a specific reason for which constants are defined outside the class, rather than using the constructor - example:</p>
  
  <pre><code>public function __construct(){
      $this-&gt;conn = mysql_connect('localhost', 'username', 'password');
      $this-&gt;db = mysql_select_db('database',$this-&gt;conn);
  }
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>public function __construct($which_db){
          if($which_db=='firstdb'){
              $server='localhost';
              $username='user1';
              $password='pass1';
              $database='db1';
          }elseif($which_db=='otherdb'){
              $server='localhost';
              $username='user2';
              $password='pass2';
              $database='db2';
          }
  
      $this-&gt;conn = mysql_connect($server, $username, $password);
      $this-&gt;db = mysql_select_db($database,$this-&gt;conn);
  
  }
  </code></pre>
  
  <p>Or using a switch or whatever.</p>
  
  <p>What is the difference between the two methods? Which would you recommend? Thanks a lot :-)</p>