- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
112 lines
2.8 KiB
PHP
112 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Database;
|
|
|
|
use App\Framework\Database\Exception\DatabaseException;
|
|
use App\Framework\Database\ValueObjects\SqlQuery;
|
|
|
|
final class PdoConnection implements ConnectionInterface
|
|
{
|
|
private \PDO $pdo;
|
|
|
|
public function __construct(\PDO $pdo)
|
|
{
|
|
$this->pdo = $pdo;
|
|
|
|
# SOllte bereits aus den Options kommen!
|
|
#$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
|
#$this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
public function execute(SqlQuery $query): int
|
|
{
|
|
try {
|
|
$statement = $this->pdo->prepare($query->sql);
|
|
$statement->execute($query->parameters->toPdoArray());
|
|
|
|
return $statement->rowCount();
|
|
} catch (\PDOException $e) {
|
|
throw DatabaseException::simple("Failed to execute query: {$e->getMessage()}", $e);
|
|
}
|
|
}
|
|
|
|
public function query(SqlQuery $query): ResultInterface
|
|
{
|
|
try {
|
|
$statement = $this->pdo->prepare($query->sql);
|
|
$statement->execute($query->parameters->toPdoArray());
|
|
|
|
return new PdoResult($statement);
|
|
} catch (\PDOException $e) {
|
|
$debug = $query->toDebugString();
|
|
|
|
throw DatabaseException::simple("Failed to execute query: {$e->getMessage()} --- Debug: {$debug}", $e);
|
|
}
|
|
}
|
|
|
|
public function queryOne(SqlQuery $query): ?array
|
|
{
|
|
$result = $this->query($query);
|
|
|
|
return $result->fetch();
|
|
}
|
|
|
|
public function queryColumn(SqlQuery $query): array
|
|
{
|
|
$result = $this->query($query);
|
|
|
|
return $result->fetchColumn();
|
|
}
|
|
|
|
public function queryScalar(SqlQuery $query): mixed
|
|
{
|
|
$result = $this->query($query);
|
|
|
|
return $result->fetchScalar();
|
|
}
|
|
|
|
public function beginTransaction(): void
|
|
{
|
|
try {
|
|
$this->pdo->beginTransaction();
|
|
} catch (\PDOException $e) {
|
|
throw DatabaseException::simple("Failed to begin transaction: {$e->getMessage()}", $e);
|
|
}
|
|
}
|
|
|
|
public function commit(): void
|
|
{
|
|
try {
|
|
$this->pdo->commit();
|
|
} catch (\PDOException $e) {
|
|
throw DatabaseException::simple("Failed to commit transaction: {$e->getMessage()}", $e);
|
|
}
|
|
}
|
|
|
|
public function rollback(): void
|
|
{
|
|
try {
|
|
$this->pdo->rollBack();
|
|
} catch (\PDOException $e) {
|
|
throw DatabaseException::simple("Failed to rollback transaction: {$e->getMessage()}", $e);
|
|
}
|
|
}
|
|
|
|
public function inTransaction(): bool
|
|
{
|
|
return $this->pdo->inTransaction();
|
|
}
|
|
|
|
public function lastInsertId(): string
|
|
{
|
|
return $this->pdo->lastInsertId();
|
|
}
|
|
|
|
public function getPdo(): \PDO
|
|
{
|
|
return $this->pdo;
|
|
}
|
|
}
|