Mysqli connection using object
<p>I just started switching my project form the mysql to mysqli. So what i did is i just create a class db and function connect.how can i create objects and re use it</p>

<p>This is my code:</p>

<p><strong>class db:</strong></p>

<pre><code>class db {

    //global var session
    private $biz;

    //constructor
    function db (&amp;$b) {
        $this-&gt;biz = $b;            
        $this-&gt;connect();
    }

    function connect() {
        mysqli_connect(
              $this-&gt;biz-&gt;_db['host']
            , $this-&gt;biz-&gt;_db['username']
            , $this-&gt;biz-&gt;_db['password']
                        ,$this-&gt;biz-&gt;_db['database']
        ) or die("Unable to connect to database");

        //$cont=mysqli_select_db($con,$this-&gt;biz-&gt;_db['database']) or die("Unable to select database: {$this-&gt;biz-&gt;_db['database']}");
        //return $connt;
    }       

    /*
     This function will perform a simple query and return all the results
     @return        object      Object containing the rows, num_rows and result

     @param string  $sql        The SQL query
    */
    function query($sql) {

            $result = new fetchQuery($sql);
            return $result;
    }

    /*
     This function will perform a query given the sql
     @return        object      Object containing num rows affected and result

     @param string  $sql        The SQL query
    */
    function updateQuery($sql) {
        return new updateQuery($sql);
    }

    /*
     This function will perform a query given the sql
     @return        object      Object containing num rows affected and result

     @param string  $sql        The SQL query
    */
    function insertQuery($sql) {    
        return new insertQuery($sql);
    }

    /*
     This function will perform a query given the sql
     @return        object      Object containing num rows affected and result

     @param string  $sql        The SQL query
    */
    function deleteQuery($sql) {
        return new deleteQuery($sql);
    }

    /*
     This function will automatically decide if data is being updated or inserted

     @param array   $data       The post object, key/value pairs , already validated
     @param string  $table      The table to be updated
    */       

    /*
     This function will perform an update query from the post data that has the correct form - fields matching table field names
     @return        object      Object containing num rows affected and result

     @param array   $data       The post object, key/value pairs , already validated
     @param string  $table      The table to be updated
    */
    function autoUpdate($data, $table,$wheredata) {

        //id is required, return false if not found
        if (!isset($wheredata)) 
        {
            return false;
        }  

        $sql = "
            UPDATE
                `$table`
            SET
        ";

        foreach ($data as $key =&gt; $value) {          
                $sql .= " `$key` = '$value' ,";     
        }

        //remove extra comma
        $sql = substr($sql, 0, (strlen($sql) - 1));         
        $sql .= " WHERE 0=0 ";

        foreach ($wheredata as $key =&gt; $value) {
        $sql .= " and `$key` = '$value' ";
        }

        return new updateQuery($sql);
    }

    /*
     This function will perform an insert query from the matching form table
     @return        object      Object containing num rows affected and result

     @param array   $data       The post object, key/value pairs , already validated
     @param string  $table      The table to be updated
    */
    function autoInsert($data, $table, $validate = false)
    {
        $_fields = array();
        $_values = array();

        foreach ($data as $field =&gt; $value) {
            $_fields[] = $field;
            $_values[] = $value;
        }

        $sql = "
            INSERT INTO
                `$table`
                    (
        ";

        foreach($_fields as $field) {
            $sql .= "`$field` ,";
        }

        //remove extra comma
        $sql = substr($sql, 0, (strlen($sql) - 1));

        $sql .= "
            ) VALUES (
        ";

        foreach($_values as $value) {
            $sql .= "'$value' ,";
        }

        //remove extra comma
        $sql = substr($sql, 0, (strlen($sql) - 1));

        $sql .= "
            )
        ";

        return new insertQuery($sql);
    }

    /*
     This function will perform an auto delete query from the matching form table
     @return        object      Object containing num rows affected and result

     @param int     $id         The related id
     @param string  $table      The table to be affected
    */
    function autoDelete($sql) {         
        return new deleteQuery($sql);       }
}
</code></pre>

<p><strong>fetch query:</strong></p>

<pre><code>class fetchQuery {

    public $result;
    public $num = 0;
    public $rows = array();
    public $error = false;

    function fetchQuery($sql) {

        $this-&gt;result = mysql_query($sql);    

        if ($this-&gt;result) {
            $this-&gt;num = mysql_num_rows($this-&gt;result);
            if ($this-&gt;num) {
                while($row = mysql_fetch_assoc($this-&gt;result)) {
                    $this-&gt;rows[] = $row;
                }
            } else {
                $this-&gt;result = false;
            }
        } else {
            $this-&gt;result = false;
            $this-&gt;error  = mysql_error();
        }
    }
</code></pre>

<p>please give me a solution for create fetch query using connect function.</p>