PHP MySQLi database object I've been learning more about PHP Objects and Classes, and my immediate reaction was to create a Database Object for handling the MySQLi Connection, Statements and Results.  Its not meant to be an ultimate do-all object, but help with WET code.  Obviously this has been done before... at least a hundred times.  

There's no question lingering on whether I should be doing this, my question is more along the lines of am I doing this right?.

Basically I don't want to write out 10+ lines of code each time I make an SQL statement, let alone deal with the other functions that take place.  So I made an object that can do the SQL connection, statement, and get results.  The goal was to make the interaction as simple as possible and I like to think I achieved that.  Thoughts?

Usage:

Create the Object

$db = new Sqli();

Execute a Statement

$db-&gt;statement($sql, $param)

$db-&gt;statement("SELECT column_name FROM table WHERE = ?", "bind_me")

$db-&gt;statement("INSERT INTO table (col1, col2, col3) VALUES (?, ?, ?)", [$foo, $bar, $baz]);

Print Results

print_r($db-&gt;result());

JSON Result

print json_encode($db-&gt;result());

PHP Code:

class Sqli
{
    const DBHOST = "localhost";
    const DBUSER = "";
    const DBPASS = "";
    const DBNAME = "";

    protected $conn;
    protected $stmt;

    function __construct()
    {
        $this-&gt;setConnection();
    }

    private function setConnection()
    {
        mysqli_report(MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR);
        try
        {
            $conn = new mysqli(
                self::DBHOST, 
                self::DBUSER, 
                self::DBPASS, 
                self::DBNAME
            );
        }
        catch(MySQLi_sql_exception $e)
        {
            throw new \MySQLi_sql_exception(
                $e-&gt;getMessage(), 
                $e-&gt;getCode()
            );
        }
        $this-&gt;conn = $conn;
    }

    public function statement($sql, $param)
    {
        $stmt   = $this-&gt;conn-&gt;prepare($sql);

        if($param !== FALSE)
        {

            if(!is_array($param))
            {
                $param = [$param];
            }

            $types = str_repeat("s", count($param));

            $stmt-&gt;bind_param($types, ...$param);
        }

        $stmt-&gt;execute();

        $stmt-&gt;store_result();

        $this-&gt;stmt = $stmt;
    }

    public function result()
    {
        $stmt = $this-&gt;stmt;

        $meta = $stmt-&gt;result_metadata();

        while($field = $meta-&gt;fetch_field())
        {
            $param[] = &amp;$row[$field-&gt;name];
        }

        call_user_func_array([$stmt, "bind_result"], $param);

        while($stmt-&gt;fetch())
        {

            foreach($row as $key =&gt; $val)
            {
                $r[$key] = filter_var($val, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_ENCODE_HIGH|FILTER_FLAG_ENCODE_LOW|FILTER_FLAG_ENCODE_AMP);
            }
            $result[] = $r;
        }

        return $result;
    }
}
Dont call private methods in constructor, put the code into the constructor directly (well unless you have reason to call the same piece of code from elsewhere too, not your case tho).

Don't put your db credentials into the class's constants. This way you are unable to use the class to connect to any other database. Well you can change their values, but that means change the code, or you can extend the class and override the constants. But that's also not very convenient.

You might want to prefer PDO instead of the mysqli extension. The PDO contains mysql adapter in it (maybe you need pdo_mysql extension i think). But you will have the freedom to change the underlying database transparently anytime (well unless you are using some specific sql dialect features).

PDO basically offers the same as your class does, except it has no hardcoded credentials, which, as I already mentioned, is bad.

So learn to use PDO and you may find out that you need no such wrapper at all, you just need a place where you pass the right credentials to its contructor. This place could be described as database connection factory.