title: MySQLi won't authenticate with localhost, but MySQL_connect will
body: <p>I am upgrading a server from vulnerable <code>mysql_*</code> functions to better <code>$mysqli-&gt;</code> functions, but I've run into a problem at the very beginning. I have something like this:</p>
  
  <pre><code>$host = "localhost";
  $u = "user";
  $p = "pass";
  $db = "database";
  </code></pre>
  
  <p>The old connection protocol looks like this:</p>
  
  <pre><code>$link = mysql_connect($host, $u, $p);
  if(!$link){die();}
  mysql_select_db($db);
  </code></pre>
  
  <p>This works just fine. I can connect, authenticate, and access the database. However, this code:</p>
  
  <pre><code>$link = new mysqli($host, $u, $p, $db);
  if(!$link){die();}
  </code></pre>
  
  <p>This results in an Access Denied for user xxxxx@localhost (using password: YES) error.</p>
  
  <p>I have made used mysqli so many times, but I've never had this happen.</p>
  
  <h2>Additional things I've tried</h2>
  
  <ul>
  <li>Specifying port 3306 does not help</li>
  <li>Specifying the WAN IP does not help</li>
  <li>mysqli_connect</li>
  <li>127.0.0.1</li>
  </ul>
  
  <h2>Mysqli settings:</h2>
  
  <pre><code>MysqlI Support =&gt; enabled
  Client API library version =&gt; 5.1.54
  Active Persistent Links =&gt; 0
  Inactive Persistent Links =&gt; 0
  Active Links =&gt; 0
  Client API header version =&gt; 5.1.54
  MYSQLI_SOCKET =&gt; /var/lib/mysql/mysql.sock
  
  Directive =&gt; Local Value =&gt; Master Value
  mysqli.allow_local_infile =&gt; On =&gt; On
  mysqli.allow_persistent =&gt; On =&gt; On
  mysqli.default_host =&gt; no value =&gt; no value
  mysqli.default_port =&gt; 3306 =&gt; 3306
  mysqli.default_pw =&gt; no value =&gt; no value
  mysqli.default_socket =&gt; no value =&gt; no value
  mysqli.default_user =&gt; no value =&gt; no value
  mysqli.max_links =&gt; Unlimited =&gt; Unlimited
  mysqli.max_persistent =&gt; Unlimited =&gt; Unlimited
  mysqli.reconnect =&gt; Off =&gt; Off
  </code></pre>
  
  <h2>Update</h2>
  
  <ul>
  <li>MYSQL_SOCKET = MYSQLI_SOCKET</li>
  <li>Specifying the socket manually in the new mysqli does nothing</li>
  <li>Adding extension=mysqli.so to the php.ini did nothing.</li>
  <li>Restarting Apache after all of this did nothing.</li>
  </ul>