title: Specifying socket option on mysqli_connect
body: <p>I have two <code>mysql.sock</code> file.</p>
  <p>One is at <code>/opt/lampp/var/mysql/mysql.sock</code>.</p>
  <p>Another one is at <code>/var/run/mysqld/mysqld.sock</code>.</p>
  <p>I want to create a connection using first mysql.sock file.</p>
  <p>I also set the default_socket in <code>php.ini</code>.</p>
  <p>But it always connect to second one.</p>
  <p>The program won't be error, even if I use wrong path of <code>mysql.sock</code>.</p>
  <p>This is my code:</p>
  <pre><code>&lt;?php
  $servername = &quot;127.0.0.1&quot;;
  $username = &quot;my_username&quot;;
  $password = &quot;my_password&quot;;
  $database = &quot;&quot;;
  $port = &quot;3306&quot;;
  $socket = &quot;/opt/lampp/var/mysql/mysql.sock&quot;;
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $database, $port, $socket);
  
  //Check the host info
  echo $conn-&gt;host_info.&quot;\n&quot;;
  
  // Check connection
  if ($conn-&gt;connect_errno) {
      printf(&quot;Connect failed: %s\n&quot;, $conn-&gt;connect_error);
      exit();
  }
  
  $conn-&gt;query(&quot;set character set utf8&quot;);
  
  //Which socket did I connect?
  $result = $conn-&gt;query(&quot;SHOW VARIABLES WHERE Variable_name = 'socket';&quot;);
  $row = mysqli_fetch_assoc($result);
  echo $row['Value'].&quot;\n&quot;;
  
  //Check the default_socket in php.ini file
  echo ini_get(&quot;mysqli.default_socket&quot;);
  ?&gt;
  </code></pre>
  <p>The output is:</p>
  <blockquote>
  <p>127.0.0.1 via TCP/IP</p>
  <p>/var/run/mysqld/mysqld.sock</p>
  <p>/opt/lampp/var/mysql/mysql.sock</p>
  </blockquote>
  <p>How to solve this problem?</p>
  <p>Update:</p>
  <pre><code>ls -l /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock
  </code></pre>
  <p>Output is</p>
  <blockquote>
  <p>srwxrwxrwx 1 mysql mysql 0  7月 13 18:10 /opt/lampp/var/mysql/mysql.sock</p>
  <p>srwxrwxrwx 1 mysql mysql 0  7月  6 21:06 /var/run/mysqld/mysqld.sock</p>
  </blockquote>