diff --git a/db/db/db.php b/db/db/db.php new file mode 100644 index 0000000..57ff632 --- /dev/null +++ b/db/db/db.php @@ -0,0 +1,80 @@ +pdo == null){ + global $db_path; + $this->pdo = new \PDO('sqlite:'.$db_path); + $this->pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + } + return $this->pdo; + } + + public function schema($schema_file){ + $sql = file_get_contents($schema_file); + $this->pdo->exec($sql); + } + + public function insert($registro){ + $columns = implode(",", array_keys($registro)); + echo $columns; + $sql = "INSERT INTO Registro ($columns)" + .' VALUES (:nombre,:apellido,:titulo,:afiliacion,:ciudad,:pais,:email,:fechaLlegada,' + .':fechaPartida,:financiacion,:invitado,:cartaInvitacion,:roomingPref,:roommate,:fechaRegistro);'; + echo $sql; + $stmt = $this->pdo->prepare($sql); + $stmt->execute([ + ':nombre' => $registro['nombre'], + ':apellido' => $registro['apellido'], + ':titulo' => $registro['titulo'], + ':afiliacion' => $registro['afiliacion'], + ':ciudad' => $registro['ciudad'], + ':pais' => $registro['pais'], + ':email' => $registro['email'], + ':fechaLlegada' => $registro['fechaLlegada'], + ':fechaPartida' => $registro['fechaPartida'], + ':financiacion' => $registro['financiacion'], + ':invitado' => $registro['invitado'], + ':cartaInvitacion' => $registro['cartaInvitacion'], + ':roomingPref' => $registro['roomingPref'], + ':roommate' => $registro['roommate'], + ':fechaRegistro' => $registro['fechaRegistro'] + ]); + return $this->pdo->lastInsertId(); + + } + public function getAll(){ + $stmt = $this->pdo->prepare("SELECT * FROM Registro"); + $stmt -> execute(); + return $stmt->fetchAll(\PDO::FETCH_BOTH); + + } + public function findByMail($email){ + $stmt = $this->pdo->prepare("SELECT * FROM Registro WHERE email=:email"); + $stmt->bindParam(":email",$email); + $stmt->execute(); + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + if($result) + return false; + else + true; + } + + + + } + + $db = new DB(); + $db->connect(); + $db->schema($schema_path); + + + +?> + diff --git a/db/db/ggdworkshop.db b/db/db/ggdworkshop.db new file mode 100644 index 0000000..e88f41d Binary files /dev/null and b/db/db/ggdworkshop.db differ diff --git a/db/db/schema.sql b/db/db/schema.sql new file mode 100644 index 0000000..71e2be6 --- /dev/null +++ b/db/db/schema.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS Registro + ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + nombre VARCHAR(50) NOT NULL, + apellido VARCHAR(50) NOT NULL, + titulo VARCHAR(50), + afiliacion VARCHAR(50), + ciudad VARCHAR(50), + pais VARCHAR(50), + email VARCHAR(80) NOT NULL UNIQUE, + fechaLlegada DATE, + fechaPartida DATE, + financiacion BOOLEAN NOT NULL, + invitado BOOLEAN NOT NULL, + cartaInvitacion BOOLEAN NOT NULL, + roomingPref VARCHAR(50), + roommate VARCHAR(50), + fechaRegistro DATETIME NOT NULL + ); \ No newline at end of file