-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
joelsalisbury
committed
Dec 7, 2016
1 parent
feb7c27
commit 97b1c1e
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
class Diagnosis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
function getDatabase() { | ||
// tells php that the database lives on the same server as the php file | ||
//$dbhost = "localhost"; | ||
$dbhost = "develop.digitalmediauconn.org"; | ||
|
||
// this is the username | ||
$dbuser = "abxrls"; | ||
|
||
// this is the password | ||
$dbpass = "abxrls"; | ||
|
||
// name of the DB that we set up together | ||
$dbname = "ccmc_antibiotics"; | ||
|
||
// this just makes a little config line for PHP to read | ||
$mysql_conn_string = "mysql:host=$dbhost;dbname=$dbname"; | ||
|
||
//setup a new connection using the stuff up above | ||
$database = new PDO($mysql_conn_string, $dbuser, $dbpass); | ||
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
|
||
return $database; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
require_once 'diagnosis.php'; | ||
|
||
$diag_id = $_GET['id']; | ||
|
||
$diag = new Diagnosis($diag_id); | ||
|
||
echo "<pre>"; | ||
print_r($diag->get()); | ||
echo "</pre>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
include 'database.php'; | ||
class Diagnosis { | ||
|
||
protected $id; | ||
protected $name; | ||
protected $notes; | ||
protected $relatedAntibiotics; | ||
|
||
public function __construct($id=0) { | ||
if ($id !== 0) { | ||
$db = getDatabase(); | ||
$query = $db->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; | ||
} | ||
|
||
} |