HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/deensekroon.komma-mediadesign.nl/wwwroot/App/Core/Repository.php
<?php


namespace App\Core;


abstract class Repository
{
    /**
     * @var \mysqli
     */
    protected $mysqli;

    /**
     * @var string
     */
    protected $error;

    /**
     * Repository constructor.
     */
    public function __construct()
    {
        global $mysqli;
        $this->mysqli = $mysqli;
    }

    /**
     * Return error to the user
     *
     * @return mixed
     */
    public function error()
    {
        return $this->error;
    }


    /**
     * Return result as Array
     *
     * @param $query
     * @return array|bool
     */
    public function result($query)
    {
        // Prepare statement
        if( ! $statement = $this->mysqli->prepare($query))
        {
            $this->error = $this->mysqli->error;
            return false;
        }

        // Execute en get result
        $statement->execute();
        $result = $statement->get_result();
        $statement->close();

        return $result;
    }

    /**
     * @param $result
     * @return array
     */
    public function rows($result)
    {
        // Push result in array
        $rows = [];
        while ($row = $result->fetch_object())
        {
            $rows[] = $row;
        }

        return $rows;
    }
}