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;
}
}