File: /var/www/vhosts/creativefellows.nl/fvr.creativefellows.nl/src/Domain/Repository.php
<?php
namespace App\Domain;
use PDO;
/**
* Repository.
*/
abstract class Repository
{
/**
* @var PDO The database connection
*/
private $connection;
/**
* Constructor.
*
* @param PDO $connection The database connection
*/
public function __construct(PDO $connection)
{
$this->connection = $connection;
$this->connection->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
}
/**
* 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 ? : [];
}
/**
* 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 ? : [];
}
}