/** * Handles a normal/general exception and terminate the script * * @access public * @static * @param exception $generalException Instanz of an exception */ public function handleException($generalException) { /* delegate - static call */ phpmediadb_exception::showError($generalException); /* sorry, have to kill script - no way i can fix it */ die; }
/** * This function returns true when the record exists * and false when the record doesn't exist * * @access public * @param Integer $id contains specified id for the sql statement * @return bool returns whether the specified record exists */ public function exist($id) { /* init */ $returnValue = false; try { $conn = $this->DATA->SQL->getConnection(); $stmt = $conn->prepareStatement('SELECT COUNT(*) FROM MediaStatus WHERE MediaStatus.MediaStatusID = ?'); $stmt->setString(1, $id); $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); $rs->next(); /* check if item exists */ if ($rs->get(1) >= 1) { $returnValue = true; } return $returnValue; } catch (Exception $exception) { /* handle exception and terminate script */ phpmediadb_exception::handleException($exception); } }
/** * This function returns the ItemType from a specified ItemID * * @access public * @param Integer $id contains specified id for the sql statement * @return integer returns the results of database query */ public function getItemType($id) { try { $conn = $this->DATA->SQL->getConnection(); $stmt = $conn->prepareStatement('SELECT Items.ItemTypeID FROM Items WHERE Items.ItemID = ?'); $stmt->setString(1, $id); $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); if ($rs->next()) { return $rs->get(1); } else { return NULL; } } catch (Exception $exception) { /* handle exception and terminate script */ phpmediadb_exception::handleException($exception); } }
/** * This function returns the list of the parameters ItemID and CategoryID * from the table Categories_has_Items * * @access public * @param Integer $itemId contains specified id for the sql statement */ public function getLinkList($itemId) { try { $conn = $this->DATA->SQL->getConnection(); $stmt = $conn->prepareStatement('SELECT Categories_has_Items.*, Categories.* FROM Categories_has_Items LEFT JOIN Categories ON Categories.CategoryID=Categories_has_Items.CategoryID WHERE Categories_has_Items.ItemID = ?'); $stmt->setString(1, $itemId); $rs = $stmt->executeQuery(); return $this->DATA->SQL->generateDataArray($rs); } catch (Exception $exception) { /* handle exception and terminate script */ phpmediadb_exception::handleException($exception); } }
/** * This function returns the id of the last created record in a table * * @access public * @param String $conn contains information from the connection to the database * @return Integer returns the id from the last created record */ public function getLastInsert($conn) { try { /* get ID-generator */ $idGen = $conn->getIdGenerator(); /* return last inserted id */ return $idGen->getId(); } catch (Exception $e) { /* handle exception and terminate script */ phpmediadb_exception::handleException($ex); } }
/** * This function deletes a specified record from the table AudioDatas * and all depending data from the other tables * * @access public * @param Integer $id contains specified id for the sql statement * @return bool Status of transaction */ public function delete($id) { try { $conn = $this->DATA->SQL->getConnection(); $this->DATA->SQL->openTransaction($conn); $stmt = $conn->prepareStatement('DELETE VideoDatas, Items, BinaryDatas, Categories_has_Items FROM Items LEFT JOIN VideoDatas ON VideoDatas.ItemID=Items.ItemID LEFT JOIN Categories_has_Items ON Categories_has_Items.ItemID=Items.ItemID LEFT JOIN BinaryDatas ON BinaryDatas.ItemID=Items.ItemID WHERE Items.ItemID = ?'); $stmt->setString(1, $id); $rs = $stmt->executeUpdate(); $this->DATA->SQL->commitTransaction($conn); } catch (Exception $exception) { /* rollback transaction */ $this->DATA->SQL->rollbackTransaction($conn); /* handle exception and terminate script */ phpmediadb_exception::handleException($exception); } return true; }