Custom MySQLi connector class for PHP I have written a class that connects to a database using MySQLi and has methods for the connection itself and returns the instance of the MySQLi class. 

This works, but feels a little "clunky" and can be a bit slow, can someone help me to improve this?

The class is as follows:

&lt;?php

/**
 * Connect to a db.
 */
class mysqli_connector
{
    /** Private to implement Singleton pattern */
    private function __construct() {  }

    private static $init;

    /** @return mysqli_connector */
    public static function Init()
    {
        return static::$init = (
                null === static::$init ? new self() : static::$init
            );
    }
    /** @var mysqli */
    private static $link;
    /**
     * Sets and gets the link to the database based on params
     * @param string $host 
     * @param string $username 
     * @param string $password 
     * @param string $dbname 
     * @return mysqli
     */
    public function link($host = '', $username = '', $password = '', $dbname = '')
    {
        static::$link = mysqli_init();
        if ($host != '' &amp;&amp; $username != '' &amp;&amp; $password != '' &amp;&amp; $dbname != '')
        {
            static::$link-&gt;real_connect($host, $username, $password, $dbname);
        }
        else if ($host != '' &amp;&amp; $username != '' &amp;&amp; $password != '' &amp;&amp; $dbname == '')
        {
            static::$link-&gt;real_connect($host, $username, $password);
        }
        else if ($host != '' &amp;&amp; $username != '' &amp;&amp; $password == '' &amp;&amp; $dbname == '')
        {
            static::$link-&gt;real_connect($host, $username);
        }
        else if ($host != '' &amp;&amp; $username == '' &amp;&amp; $password == '' &amp;&amp; $dbname == '')
        {
            static::$link-&gt;real_connect($host);
        }
        else 
        {
            static::$link-&gt;real_connect();
        }
        return static::$link;
    }
}


EDIT

I use the class as such: 

&lt;?php

require_once 'include/class/_db/mysqli-connector.php';

$connector = mysqli_connector::Init();
$link = $connector-&gt;link("myhost", "mysuser", "mypass", "mydbname");
var_dump($link); # Make sure it works!

?&gt;


Output from the var_dump($link);

object(mysqli)[2]
    public 'affected_rows' =&gt; int 0
    public 'client_info' =&gt; string 'mysqlnd 5.0.11-dev - 20120503 - $Id: /* removed for security */ $' (length=79)
    public 'client_version' =&gt; int 50011
    public 'connect_errno' =&gt; int 0
    public 'connect_error' =&gt; null
    public 'errno' =&gt; int 0
    public 'error' =&gt; string '' (length=0)
    public 'error_list' =&gt;
        array (size=0)
            empty
    public 'field_count' =&gt; int 0
    public 'host_info' =&gt; string 'localhost via TCP/IP' (length=20)
    public 'info' =&gt; null
    public 'insert_id' =&gt; int 0
    public 'server_info' =&gt; string '5.6.26' (length=6)
    public 'server_version' =&gt; int 50626
    public 'stat' =&gt; string 'Uptime: 118450  Threads: 1  Questions: 149  Slow queries: 0  Opens: 70  Flush tables: 1  Open tables: 63  Queries per second avg: 0.001' (length=135)
    public 'sqlstate' =&gt; string '00000' (length=5)
    public 'protocol_version' =&gt; int 10
    public 'thread_id' =&gt; int 117
    public 'warning_count' =&gt; int 0
First, don't use else. Or try to avoid it. The link method can be reduced drastically by just reading the docs.

host
Can be either a host name or an IP address. Passing the NULL value or the string &quot;localhost&quot; to this parameter, the local host is assumed. When possible, pipes will be used instead of the TCP/IP protocol.

Usually, using NULL in a variable will help you achieve the default behavior of things. Take advantage of it.
/**
 * Sets and gets the link to the database based on params
 * @param string $host 
 * @param string $username 
 * @param string $password 
 * @param string $dbname 
 * @return mysqli
 */
public function link($host = null, $username = null, $password = null, $dbname = null)
{
    static::$link-&gt;real_connect($host, $username, $password, $dbname);
    return static::$link;
}

Secondly, why is $link static? You're already using the Singleton Pattern, to make the $link variable static is double redundant against the pattern.