title: PHP - MYSQL - test database server
body: <p>I'm learning PHP MYSQL and trying to create a database.</p>
  
  <p>I'm following this tutorial 
  <a href="http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app" rel="nofollow">http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app</a></p>
  
  <p>So far I'm testing to see if the server has access to MySQL. When I use the following code.</p>
  
  <pre><code>?php
  
  class RedeemAPI {
     private $db;
  
     // Constructor - open DB connection
     function __construct() {
         $this-&gt;db = new mysqli('localhost', 'username', 'password', 'promos');
      $this-&gt;db-&gt;autocommit(FALSE);
  }
  
  // Destructor - close DB connection
  function __destruct() {
      $this-&gt;db-&gt;close();
  }
  
  // Main method to redeem a code
  function redeem() {
      // Print all codes in database
      $stmt = $this-&gt;db-&gt;prepare('SELECT id, code, unlock_code, uses_remaining FROM rw_promo_code');
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($id, $code, $unlock_code, $uses_remaining);
      while ($stmt-&gt;fetch()) {
          echo "$code has $uses_remaining uses remaining!";
      }
      $stmt-&gt;close();
     }
  } 
  // This is the first thing that gets called when this page is loaded
  // Creates a new instance of the RedeemAPI class and calls the redeem method
  $api = new RedeemAPI;
  $api-&gt;redeem();
  
  ?
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/user/Sites/promos/index.php on line 8
  
  Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): No such file or directory in /Users/user/Sites/promos/index.php on line 8
  
  Warning: mysqli::autocommit() [mysqli.autocommit]: Couldn't fetch mysqli in /Users/user/Sites/promos/index.php on line 9
  
  Warning: mysqli::prepare() [mysqli.prepare]: Couldn't fetch mysqli in /Users/user/Sites/promos/index.php on line 20
  
  Fatal error: Call to a member function execute() on a non-object in /Users/user/Sites/promos/index.php on line 21
  </code></pre>
  
  <p>Did I perhaps forget to enable something?</p>
  
  <p>It might explain why I cannot connect via my IP address to sequel pro and only to 127.0.0.1?</p>