function findEmptyKey($table, $column) { $j = false; @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; exit; } else { $db->select_db("UMBRELLA"); $query = "select " . $column . " from " . $table; $result = $db->query($query); $num_result = $result->num_rows; $d = array(); for ($i = 0; $i < $num_result; $i++) { $row = $result->fetch_assoc(); //echo "<p>".$row[$column]."</p>"; $d[$i] = $row[$column]; } //echo "<p>Number of results: ".$num_result."</p>"; sort($d); for ($z = 0; $z < $num_result; $z++) { if ($z != $d[$z]) { $j = $z; break; } } if ($j == false) { $j = count($d); } } $db->close(); return $j; }
public function read($id) { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Compound_>read()</p>"; $db->select_db("UMBRELLA"); $result = $db->query('select compound_id from COMPOUND'); $num_results = $result->num_rows; $a = false; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); if ($id == $row['compound_id']) { //echo "<p>Exists!</p>"; $a = true; break; } } if (!is_integer(intval($id))) { $a = false; } if ($a == false) { //echo "<p>Id does not exist!<p>"; $db->close(); return false; } $query = "select * from COMPOUND where compound_id = " . $id; $result = $db->query($query); $row = $result->fetch_assoc(); $this->__set('compound_id', $row['compound_id']); $this->__set('name', $row['name']); $this->__set('value', $row['value']); $this->__set('metric', $row['metric']); //echo "<p> Query : ".$query."</p>"; $result = $db->query($query); //echo "<p>Error message: ".mysql_error()."</p>"; @$db->close(); return true; } }
function setCompounds($option) { if ($option == 'EXISTING') { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) $db->select_db("UMBRELLA"); $result = $db->query('select * from DOSAGE_DETAILS natural join COMPOUND where dosage_id = ' . $this->__get('dosage_id')); $num_results = $result->num_rows; //echo "<p>Number of compounds: ".$num_results."</p>"; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); $this->compounds[$i] = new compound(); $this->compounds[$i]->read($row['compound_id']); //echo "<p>Compound that existed was set</p>"; } $db->close(); return true; } } elseif ($option == 'NEW') { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Successful DB read connection</p>"; $db->select_db("UMBRELLA"); $result = $db->query('select * from COMPOUND where compound_id = 0'); $num_results = $result->num_rows; //echo "<p>Number of compounds: ".$num_results."</p>"; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); $this->compounds[$i] = new compound(); $this->compounds[$i]->read($row['compound_id']); } //echo "<p>New compounds set</p>"; $db->close(); return true; } } return $this->compounds; }
public function read($id) { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Successful DB read connection</p>"; $db->select_db("UMBRELLA"); $result = $db->query('select demographic_id from DEMOGRAPHIC'); $num_results = $result->num_rows; $a = false; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); if ($id == $row['demographic_id']) { //echo "<p>Exists!</p>"; $a = true; break; } } if (!is_integer(intval($a))) { $a = false; } if ($a == false) { echo "<p>Id does not exist!<p>"; $db->close(); return false; } $query = "select * from DEMOGRAPHIC where demographic_id = " . $id; $result = $db->query($query); $row = $result->fetch_assoc(); $this->__set('demographic_id', $row['demographic_id']); $this->__set('user_id', $row['user_id']); $this->__set('ethnicity', $row['ethnicity']); $this->__set('gender', $row['gender']); $this->__set('illness', $row['illness']); $this->__set('dob', $row['dob']); //echo "<p> Query : ".$query."</p>"; $result = $db->query($query); //echo "<p>Error message: ".mysql_error()."</p>"; @$db->close(); return true; } }
function setDosages($option) { if ($option == 'EXISTING') { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Successful Getting Dosages DB read connection</p>"; $db->select_db("UMBRELLA"); //echo "<p>Successful Getting Dosages DB DB select</p>"; //where product_id = '.$this->__get('product_id') $result = $db->query("select * from DOSAGE where product_id = " . $this->__get('product_id')); //echo "<p>Successful Getting Dosages DB Query</p>"; $num_results = $result->num_rows; //echo "<p>Number results from dosages query: ".$num_results."</p>"; for ($i = 0; $i < $num_results; $i++) { //echo "<p>Fetching a dosage : ".$i."</p>"; $row = $result->fetch_assoc(); //echo "<p>fetch_assoc... row id : ".$row['dosage_id']."</p>"; $this->dosages[$i] = new dosage(); //echo "<p>Error message: ".mysql_error()."</p>"; $this->dosages[$i]->read($row['dosage_id']); //echo "<p>The dosage is called : ".$this->dosages[$i]->__get('form')."</p>"; } $db->close(); return true; //$db->close(); } } elseif ($option == 'NEW') { $this->dosages[0] = new dosage(); //FUTURE NOTE, SPECIFY A READ OPTION $this->dosages[0]->_default($this->__get('product_id')); /*$this->dosages[0]->__set('dosage_id', findEmptyKey('DOSAGE', 'dosage_id')); $this->dosages[0]->__set('product_id', $this->__get('product_id')); $this->dosages[0]->setCompounds('NEW'); */ return true; } else { return false; } //FUTURE, CREATE ADDITIONAL METHOD THAT ALLOWS THE DEVELOPER TO MANUALLY SET DOSAGES }