From f4a3010c3ffb393dab704a77ac0326908e1baa08 Mon Sep 17 00:00:00 2001 From: sabelo Date: Sun, 28 Jul 2024 18:23:30 -0300 Subject: [PATCH] adds database --- db/db/db.php | 80 +++++++++++++++++++++++++++++++++++++++++++ db/db/ggdworkshop.db | Bin 0 -> 16384 bytes db/db/schema.sql | 19 ++++++++++ 3 files changed, 99 insertions(+) create mode 100644 db/db/db.php create mode 100644 db/db/ggdworkshop.db create mode 100644 db/db/schema.sql 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 0000000000000000000000000000000000000000..e88f41d799ed345446602a3748fa17fa45f1e0bc GIT binary patch literal 16384 zcmeI3O>g2x7{~26OCW-EqpG4Qq8S>kNVJ;-a99FTC0L4BRNj_AD|(3rJius;o%jVc zM-Hu2^$S$$C+Jt`u|4$CYrjA*m3r){$Bqp)FQI7L-l}JW8IS!ukN@+V8Kh?{u3uHD zNzg#k$Jj&?_ZG+VTpl5g}0*|-ut_Hk30MINl5&Y6N2Ax!QaK7SOofutK0I_`*-0@?8`66k^;dEJ?XB$el&h{(5t_*eVs;CDbmw zsFu*0?TL!Vxj@Ng;w!pp>>i@oT7T8jq06h zbzzNfiK0+hbM3cVo7A)v&vqsDQpf>SDDG2DodsPAxiIQeOU6r`+-P)*so@H<>y1Wa zjH$9@ppuZt~f3Z!0pz$rj4mOZ0cm-Jl*X&8|p=8Y$KL*doyCAk;B8C zjdLFDO0DG07-xE&UhMe7#VF5FRVJU$mjJd*&1v7b{x?bYOkj)6Z!fqIJAA=QP8>Y` z;qiXx%iu4p0R;#E0U!VbfB+Bx0zd!=00AH{Cop~AcfcJU9(7|8DHikl{gIGVvy(El zMW{}VrmhW$VQ6|sr4ynXELoG0Opt<6i`@SBeNUl%jLuM})hTxh-I}JFWI|=4b#!ZJ z;rlU*MW{Kl@XCMRWcsqFOp z(E%4djx&LAN8sTT=^Cph#Y1f-v_GQ#QCVlYu1!lOs)_!kR%0GEZ!6uT@_K}IA{SZC zO%zntbXoHRr&01MmymL)#FXDX;KFamvysSAEEWg^7||v%iQdHOipn}+K#3}|b&N?)vfk8{^RGG z`vb@CNH4KIA@`|IvBFS1oR8)`(gvtTjn~-JRQh@$*4wN>h>e>aBR}@c&WUVoV!Gsn z4SC>cOrb;~m&)W4$!VBpY;BE^jH5B)YW(LC=Zj<}?+w(=NBp6(WSULBeYU23;vFY` zC;lw{Cf