title: Choose which database connection to run
body: <p>so i'm having my database connection in my project. The file has a local and an online request, one is commented out when i work on localhost.</p>
  
  <p>is there a way in php for it to look up which one it has to use?</p>
  
  <p>like if url = localhost/blabla use local else use online?</p>
  
  <p>Here is the connection.</p>
  
  <pre><code>try{
      //local connection
      $db = new PDO('mysql:host = 127.0.0.1; dbname=XXXX', 'root','');
  
      //local online
      //$db = new PDO('mysql:host = XXXXX; dbname=XXXXX', 'xxxxx','*****');
  
      $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }catch(PDOException $e){
      echo $e-&gt;getMessage();
      die();
  }
  $db-&gt;exec("set names utf8");
  
  if (session_status() == PHP_SESSION_NONE) {
      session_start();
  }
  </code></pre>
  
  <p>Hope somone can help if it's possible, thanks</p>