MySQL connection via Unix socket works with mysqli but not with PDO
<p>I'm using MAMP 5.5.42 with PHP 5.6.7 on my Mac OS 10.11.3. The code snippet is as follows :</p>

<pre><code>try{
$db = new PDO('mysql:host=localhost:8889;dbname=lacolshow_database;charset=utf8', 'root', 'root');
}
catch (PDOException $e) {
    var_dump($e-&gt;getMessage());
}
</code></pre>

<p>The code above raises no exception, but produces an empty PDO object.</p>

<p>If <code>localhost:8889</code> is replaced by just <code>localhost</code> in the code above, an exception is raised with message
<code>SQLSTATE[HY000] [2002] No such file or directory</code>.</p>

<p>If <code>localhost:8889</code> is replaced by <code>127.0.0.1</code> in the code above, an exception is raised with message
<code>SQLSTATE[HY000] [2002] Connection refused</code>.</p>

<p>Any help appreciated.</p>

<p><strong>Update:</strong> the connection works  if I use mysqli instead of PDO :</p>

<pre><code>$mysqli=mysqli_connect('localhost', 'root', 'root', 'lacolshow_database', NULL, '/Applications/MAMP/tmp/mysql/mysql.sock');
</code></pre>

<p>Following the advice given in the second comment at <a href="http://php.net/manual/en/pdo.construct.php" rel="nofollow">http://php.net/manual/en/pdo.construct.php</a>, I tried the following :</p>

<pre><code>$dsn = 'mysql:dbname=lacolshow_database;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock';
$db = new PDO($dsn,'root', 'root');
</code></pre>

<p>but that fails too, producing an empty PDO object.</p>