Use PDO singleton
This commit is contained in:
@@ -18,11 +18,10 @@ class DocumentList
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param PDO|null $pdo The database connection against which the query was opened
|
||||
* @param PDOStatement|null $result The result of the query
|
||||
* @param Mapper<TDoc> $mapper The mapper to deserialize JSON
|
||||
*/
|
||||
private function __construct(private ?PDO $pdo, private ?PDOStatement $result, private Mapper $mapper) { }
|
||||
private function __construct(private ?PDOStatement &$result, private readonly Mapper $mapper) { }
|
||||
|
||||
/**
|
||||
* Construct a new document list
|
||||
@@ -35,8 +34,8 @@ class DocumentList
|
||||
*/
|
||||
public static function create(string $query, array $parameters, Mapper $mapper): static
|
||||
{
|
||||
$pdo = Configuration::dbConn();
|
||||
return new static($pdo, Custom::runQuery($query, $parameters, $pdo), $mapper);
|
||||
$stmt = &Custom::runQuery($query, $parameters);
|
||||
return new static($stmt, $mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,6 +49,5 @@ class DocumentList
|
||||
while ($row = $this->result->fetch(PDO::FETCH_ASSOC)) yield $this->mapper->map($row);
|
||||
}
|
||||
$this->result = null;
|
||||
$this->pdo = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user