File: /var/www/vhosts/creativefellows.nl/mygeomil.creativefellows.nl/03072023/src/Domain/Repository.php
<?php
namespace App\Domain;
use PDO;
use Psr\Container\ContainerInterface;
/**
* Repository.
*/
abstract class Repository
{
/**
* @var PDO The database connection
*/
private $connection;
/**
* Constructor.
*
* @param PDO $connection The database connection
*/
public function __construct(
PDO $connection,
ContainerInterface $container
){
$this->connection = $connection;
$this->container = $container;
$this->items_per_page = $this->container->get("settings")["pagination"];
}
/**
* Insert user row.
*
* @param string $sql The Query
* @param array $parameters The parameters to bind
*
* @return array The array with data
*/
public function execute(string $sql, array $parameters = []): array
{
$sth = $this->connection->prepare($sql);
$sth->execute($parameters);
$row = $sth->fetch();
return $row ? : [];
}
public function insert(string $sql, array $parameters = []): int
{
$sth = $this->connection->prepare($sql);
$sth->execute($parameters);
return $this->connection->lastInsertId();
}
public function patch(string $sql, array $parameters = [])
{
$sth = $this->connection->prepare($sql);
$sth->execute($parameters);
//return $this->connection->lastInsertId();
}
/**
* Execute multiple row sql with given parameters
*
* @param string $sql The Query
* @param array $parameters The parameters to bind
*
* @return array The array with data
*/
public function executeAll(string $sql, array $parameters = []): array
{
$sth = $this->connection->prepare($sql);
$sth->execute($parameters);
$row = $sth->fetchAll();
return $row ? : [];
}
}