/** * Causes this DbData object to delete itself from the DB. * @param PDF $dbConnection The database conneciton this object will utilize to process * the deletion. * @return void * @throws Exception If an error is countered in the process, an exception will be thrown. */ public function delete(PDO $dbConnection) { $preparedStatement = $dbConnection->prepare('DELETE FROM user_preferences WHERE id = :id'); $id = parent::getId(); $preparedStatement->bindParam(':id', $id); $preparedStatement->execute(); $preparedStatement = NULL; }
protected function insert(PDO $dbConnection) { $preparedStatement = $dbConnection->prepare('INSERT INTO journey ( title, comments, creation_date ) VALUES( :title, :comments, :creationDate )'); $title = $this->getTitle(); $preparedStatement->bindParam(':title', $title); $comments = $this->getComments(); $preparedStatement->bindParam(':comments', $comments); $creationDate = date('Y-m-d H:i:s', $this->getCreationDate()); $preparedStatement->bindParam(':creationDate', $creationDate); $preparedStatement->execute(); parent::setId($dbConnection->lastInsertId()); $preparedStatement = NULL; $preparedStatement = $dbConnection->prepare('INSERT INTO journey_image_data_assoc ( journey_id, image_data_id ) VALUES( :journeyId, :imageDataId )'); foreach ($this->imageIdList as $imageId) { $preparedStatement->bindParam(':journeyId', parent::getId()); $preparedStatement->bindParam(':imageDataId', $imageId); $preparedStatement->execute(); } $preparedStatement = NULL; }
/** * This function performs an update of this object's data in the DB. * @param PDO $dbConnection The database connection this object will utilize to * process the update. * @return void * @throws Exception If an error is encountered in the process, an exception will be thrown. */ protected function update(PDO $dbConnection) { $preparedStatement = $dbConnection->prepare('UPDATE user SET password = :password, email = :email, last_login = :lastlogin, enabled = :enabled WHERE id = :id'); $password = $this->getPassword(); $preparedStatement->bindParam(':password', $password); $email = $this->getEmail(); $preparedStatement->bindParam(':email', $email); $lastLogin = date('Y-m-d H:i:s', $this->getLastLogin()); $preparedStatement->bindParam(':lastlogin', $lastLogin); $isEnabled = $this->isEnabled(); $preparedStatement->bindParam(':enabled', $isEnabled); $id = parent::getId(); $preparedStatement->bindParam(':id', $id); $preparedStatement->execute(); $preparedStatement = NULL; }
protected function update(PDO $dbConnection) { $preparedStatement = $dbConnection->prepare('UPDATE metadata_template SET species = :species, staining_method = :stainingMethod, author = :author, brain_region = :brainRegion, antibody = :antibody, comments = :comments, content_type = :content_type, template_name = :templateName WHERE id = :id'); $species = $this->getSpecies(); $preparedStatement->bindParam(':species', $species); $stainingMethod = $this->getStainingMethod(); $preparedStatement->bindParam(':stainingMethod', $stainingMethod); $author = $this->getAuthor(); $preparedStatement->bindParam(':author', $author); $brainRegion = $this->getBrainRegion(); $preparedStatement->bindParam(':brainRegion', $brainRegion); $antibody = $this->getAntibody(); $preparedStatement->bindParam(':antibody', $antibody); $comments = $this->getComments(); $preparedStatement->bindParam(':comments', $comments); $contentType = $this->getContentType(); $preparedStatement->bindParam(':content_type', $contentType); $templateName = $this->getTemplateName(); $preparedStatement->bindParam(':templateName', $templateName); $id = parent::getId(); $preparedStatement->bindParam(':id', $id); $preparedStatement->execute(); $preparedStatement = NULL; }
/** * This function performs a new insertion of this object's data into the DB. It is the implementing * class's responsibilty to set the newly generated DB id after insertion, (this is due to synchronicity * dependencies which may arise from potential insertions of child objects). * @param PDO $dbConnection The database connection this object will utilize to process * the insertion. * @return void * @throws Excetpion If an error is encountered in the process, an exception will be thrown. */ protected function insert(PDO $dbConnection) { $preparedStatement = $dbConnection->prepare('INSERT INTO image_data ( submitter_user_id, content_uri, thumbnail_uri, author, title, year ) VALUES ( :submitteruserid, :contenturi, :thumbnail, :author, :title, :year )'); $submitterUserId = $this->getSubmitterUserId(); $preparedStatement->bindParam(':submitteruserid', $submitterUserId); $contentUri = $this->getContentUri(); $preparedStatement->bindParam(':contenturi', $contentUri); $thumbnailUri = $this->getThumbnailUri(); $preparedStatement->bindParam(':thumbnail', $thumbnailUri); $author = $this->getAuthor(); $preparedStatement->bindParam(':author', $author); $title = $this->getTitle(); $preparedStatement->bindParam(':title', $title); $year = $this->getYear(); $preparedStatement->bindParam(':year', $year); $preparedStatement->execute(); $preparedStatement = NULL; parent::setId($dbConnection->lastInsertId()); foreach ($this->attributeList as $attribute) { $attribute->setImageDataId(parent::getId()); $attribute->save($dbConnection); } }