From 97b1c1e3976f3141a679682512dc60d6f1002fd4 Mon Sep 17 00:00:00 2001 From: joelsalisbury Date: Wed, 7 Dec 2016 10:49:35 -0500 Subject: [PATCH] added sample object and API file. --- api/antibiotic.php | 3 +++ api/database.php | 25 +++++++++++++++++++++++ api/diag_info.php | 11 ++++++++++ api/diagnosis.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 api/antibiotic.php create mode 100644 api/database.php create mode 100644 api/diag_info.php create mode 100644 api/diagnosis.php diff --git a/api/antibiotic.php b/api/antibiotic.php new file mode 100644 index 0000000..013b9c1 --- /dev/null +++ b/api/antibiotic.php @@ -0,0 +1,3 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + + return $database; +} \ No newline at end of file diff --git a/api/diag_info.php b/api/diag_info.php new file mode 100644 index 0000000..718ffbf --- /dev/null +++ b/api/diag_info.php @@ -0,0 +1,11 @@ +"; +print_r($diag->get()); +echo ""; \ No newline at end of file diff --git a/api/diagnosis.php b/api/diagnosis.php new file mode 100644 index 0000000..caf106f --- /dev/null +++ b/api/diagnosis.php @@ -0,0 +1,50 @@ +prepare( "SELECT * from diagnosis WHERE id = :id " ); // return all fields (*) from the table WHERE the id is the var $id passed to the function + $query->bindParam( ':id', $id ); + $query->execute(); // Run the SQL query on our database + $query->setFetchMode( PDO::FETCH_OBJ ); // A PHP method to tell the database we want to return all the data as objects with each table represented as a property of that object. This will be the case for most of our calls that return information from the database. http://php.net/manual/en/pdo.constants.php + $data = $query->fetchAll(); + + $data = $data[0]; + + // Build our local object + $this->id = $data->id; + $this->name = $data->name; + $this->notes = $data->notes; + $this->buildRelatedAntibiotics(); + } + } + + private function buildRelatedAntibiotics () { + $db = getDatabase(); + $query = $db->prepare( "SELECT * from diagnosis_antibiotic WHERE diagnosis_id = :id " ); // return all fields (*) from the table WHERE the id is the var $id of current diagnosis + $query->bindParam( ':id', $this->id ); + $query->execute(); // Run the SQL query on our database + $query->setFetchMode( PDO::FETCH_OBJ ); + $data = $query->fetchAll(); + + + $this->relatedAntibiotics = $data; + } + + public function get () { + $res['id'] = $this->id; + $res['name'] = $this->name; + $res['notes'] = $this->notes; + $res['relatedAntibiotics'] = $this->relatedAntibiotics; + + return $res; + } + +} \ No newline at end of file