PHP Prepare statement shortcut class I did some looking around and found some more topics on how to use the $stmt->bind_param function inside another function or class what means the reference variables have to be sort of passed on. With the information, I obtained I was able to create a class that allows a mysqli prepared statement with fewer lines in the code itself (faster coding) and allows for error checking in the prepared statement query. I'd like to know if this method is useful and "correct" as far as code can be correct. I've planned to add more of the prepared statement's functions to the class later on but for now, this is it. 

class db_prepare {

    public function __construct($query = false) {
        global $DB;
        $this-&gt;stmt = $DB-&gt;prepare($query);
        $this-&gt;error = false;
        if($this-&gt;stmt == false) {
            $this-&gt;error = true;
            echo $mysqli-&gt;error;
        }
    }

    public function bind_param($type, &amp;...$args) {
        if($this-&gt;error == false) {
            call_user_func_array(array($this-&gt;stmt, "bind_param"), array_merge([$type], $args));
        }

    }

    public function get_result() {
        if($this-&gt;error == false) {
            $this-&gt;stmt-&gt;execute();
            return $this-&gt;stmt-&gt;get_result();
        }
    }

    public function execute() {
        if($this-&gt;error == false) {
            return $this-&gt;stmt-&gt;execute();
        }else {
            return false;
        }
    }

    public function get_result_array() {
        $array = array();
        if($this-&gt;error == false) {
            $this-&gt;stmt-&gt;execute();
            $rows = $this-&gt;stmt-&gt;get_result();
            while($row = $rows-&gt;fetch_array()) {
                $array[] = $row;
            }
        }
        return $array;
    }

    public function close() {
        $this-&gt;stmt-&gt;close();
    }

}


This means i can call upon the class in a way like this:

$query = "SELECT * FROM `reactions` WHERE `date` = ? AND `author` = ?";
$stmt = new db_prepare($query);
$stmt-&gt;bind_param("ss", $date, $author);

$date = '2018-17-07';
$author = 'Admin';
$results = $stmt-&gt;get_result();

$date = '2018-17-07';
$author = 'Mike';
$results = $stmt-&gt;get_result();
$stmt-&gt;close();
Given the main added value in this class is a sort of error handler, I would suggest to make a little addition to your connection code that will make mysqli  report errors by itself, which will make your class pretty much obsoleted.

Just add the following line before new mysqli...

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);


and you won't need to do things like echo $mysqli-&gt;error anymore simply because mysqli will do everything you wrote here by hand.

Which means that you will perfectly do with vanilla mysqli:

$query = "SELECT * FROM `posts` WHERE `ID` = ? AND `author` = ?";
$stmt = $DB-&gt;prepare($query);
$stmt-&gt;bind_param("ss", $ID, $author);

$ID = 1;
$author = 'Admin';
$results = $stmt-&gt;get_result();

$ID = 2;
$author = 'Admin';
$results = $stmt-&gt;get_result();
$stmt-&gt;close();


and there is even get_result_array() available in mysqli out of the box:

$query = "SELECT * FROM `posts` WHERE `author` = ?";
$stmt = $DB-&gt;prepare($query);
$stmt-&gt;bind_param("s", $author);
$results = $stmt-&gt;get_result()-&gt;fetch_all();
                                ^^^^^^^^^ notice this part


What I would do if I would decide to create a prepared statement shortcut class, is a method that accepts both query and parameters executes them together, like 

$query = "SELECT * FROM `posts` WHERE `ID` = ? AND `author` = ?";
$results = DB::run($query, [$ID, $author])-&gt;get_result()-&gt;fetch_all();


such a function I would call a shortcut