title: How to return instance of MYSQLi connection object from PHP function?
body: <p>There is a problem when using MYSQLi  connection object returned from the following PHP function (PHP version 5.3.10, MYSQL version 5.5.24):</p>
  
  <pre><code>function connectDB(){
    $con=new mysqli("host","user","password","database");
    return $con;
  }
  </code></pre>
  
  <p>The function is called like this:</p>
  
  <pre><code>$mycon=connectDB();
  </code></pre>
  
  <p>The instance of connection object created with this method is not the same comparing to the one created directly without a function:</p>
  
  <pre><code>$mycon=new mysqli("host","user","password","database");
  </code></pre>
  
  <p>Output of </p>
  
  <pre><code>echo $mycon-&gt;host_info;
  </code></pre>
  
  <p>in the first case (with a function) is:</p>
  
  <pre><code>Localhost via UNIX socket
  </code></pre>
  
  <p>and in the latter case (without a function):</p>
  
  <pre><code>LOCALHOST via TCP/IP
  </code></pre>
  
  <p>Is something wrong with such method of creating a connection?</p>