1e51ef7def
- Konzept/, didaktik_geografie/, didaktik_simulation/, v2-modules/, v2-platform/ - 12 code-workspace-Files - STATUS-*.md - viele M/D/R-Änderungen an bereits getrackten Files - .gitignore verstärkt: **/.humaninput/, **/secret_keys.txt Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* V2-Plattform — DB-Zugriff (PDO-Wrapper)
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
function v2_db(): PDO {
|
|
static $pdo = null;
|
|
if ($pdo === null) {
|
|
$dsn = sprintf(
|
|
'mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4',
|
|
V2_DB_HOST, V2_DB_PORT, V2_DB_NAME
|
|
);
|
|
$pdo = new PDO($dsn, V2_DB_USER, V2_DB_PASS, [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
]);
|
|
}
|
|
return $pdo;
|
|
}
|
|
|
|
function v2_db_one(string $sql, array $params = []): ?array {
|
|
$stmt = v2_db()->prepare($sql);
|
|
$stmt->execute($params);
|
|
$row = $stmt->fetch();
|
|
return $row === false ? null : $row;
|
|
}
|
|
|
|
function v2_db_all(string $sql, array $params = []): array {
|
|
$stmt = v2_db()->prepare($sql);
|
|
$stmt->execute($params);
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
function v2_db_exec(string $sql, array $params = []): int {
|
|
$stmt = v2_db()->prepare($sql);
|
|
$stmt->execute($params);
|
|
return $stmt->rowCount();
|
|
}
|
|
|
|
function v2_db_insert_id(): string {
|
|
return v2_db()->lastInsertId();
|
|
}
|