title: Connecting PHP to mySQL on osX Sierra
body: <p>I'm quite new to <code>PHP</code> and <code>MySQL</code>. I'm using the Mac OS Sierra pre installed copies of <code>Apache</code> and <code>PHP</code>. I've downloaded and configure <code>MySQL</code> (works absolutely fine, able to use <code>CRUD</code> and so on). However, I've been struggling to connect from <code>PHP</code> to the database. I have this code:</p>
  
  <pre><code>&lt;?php
      $dbhost = "localhost";
      $dbuser = "mgs";
      $dbpass = "pass1";
      $dbname = "widget_corp";
      $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  
      if(mysqli_connect_errno()){
          die("Database connection failed " .
               mysqli_connect_error() .
               "(".mysqli_connect_errno().")"
             );
      }
  
  ?&gt;
  
  &lt;!doctype html&gt;
  
      &lt;html&gt;
          &lt;head&gt;
              &lt;title&gt;Conn&lt;/title&gt;
  
          &lt;/head&gt;
  
          &lt;body&gt;
  
  
          &lt;/body&gt;
  
      &lt;/html&gt;
  &lt;?php
      mysqli_close($connection);
  
  ?&gt;
  </code></pre>
  
  <p>I've saved it as a <code>.php</code> file
  However I keep getting this error when i try to open the <code>.php</code> file from a browser:</p>
  
  <blockquote>
    <p>Warning: mysqli_connect(): (HY000/2002): No such file or directory in
    /Users/Mahfouz/Sites/connect_prac.php on line 6 Database connection
    failed No such file or directory(2002)</p>
  </blockquote>
  
  <p>I've created the User and Database referenced in the code.
  what am I doing wrong? how do I get this working?
  thanks</p>
  
  <p>PS: I've looked at similar questions on this website, but I haven't been able to apply any of the given solutions to my situation.</p>