From 30ae1feb3d86339b3bcd2cf492d162f6c19986f1 Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Sun, 27 Dec 2020 15:27:36 +0100 Subject: [PATCH] first code --- Object.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Object.php diff --git a/Object.php b/Object.php new file mode 100644 index 0000000..688a492 --- /dev/null +++ b/Object.php @@ -0,0 +1,37 @@ +connection = new PDO("mysql:dbname=".$name.";host=".$host.":".$port, $user, $pass); + } + + public function prepare(string $query):void { + if(!$this->statement = $this->connection->prepare($query)) { + die("Prepare failed: ".$this->statement->errorInfo()[2]); + } + } + + public function bind_and_execute(array $parameters = []) { + foreach($parameters as $key => $val) { + if ($this->statement->bindValue($key, $val) === FALSE) { + die("Binding parameters failed: ".$this->statement->errorInfo()[2]); + } + } + if($this->statement->execute() === FALSE) { + die("Execute failed: ".$this->statement->errorInfo()[2]); + } + } + + public function fetch_assoc():array { + return $this->statement->fetchAll(PDO::FETCH_ASSOC); + } + }