Init: MVP de Gestión de Pagos (Stitch UI + SQLite/PHP)

This commit is contained in:
Ricardo Monla
2026-04-08 23:39:24 -03:00
commit aeceba9095
12 changed files with 870 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
// pagos/api/db.php
$db_file = __DIR__ . '/../db/finanzas.sqlite';
$schema_file = __DIR__ . '/../db/schema.sql';
// Función para obtener conexión PDO a SQLite
function getDB() {
global $db_file, $schema_file;
$is_new = !file_exists($db_file);
try {
$pdo = new PDO("sqlite:" . $db_file);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Si no existía, crear la BD desde schema y establecer permisos
if ($is_new && file_exists($schema_file)) {
$schema = file_get_contents($schema_file);
$pdo->exec($schema);
// Intentar dar permisos para www-data en el servidor
@chmod($db_file, 0666);
@chmod(dirname($db_file), 0777);
}
return $pdo;
} catch (PDOException $e) {
http_response_code(500);
die(json_encode(['error' => 'Connection failed: ' . $e->getMessage()]));
}
}
?>