コード例 #1
0
ファイル: AbstractPdoDao.php プロジェクト: centralapps/dao
 /**
  * Toggle a boolean value in a record
  * @param ModelInterface $model the model to toggle a property of
  * @param string $field_name the field to toggle
  * @throws \OutOfBoundsException
  */
 public function toggleBoolean(ModelInterface $object, $field_name)
 {
     $sql = "UPDATE\n                    `{$this->tableName}`\n                SET\n                    `{$field_name}` = (1 - `{$field_name}`)\n                WHERE\n                    `{$this->uniqueReferenceField}`=:unique_reference\n                ";
     $statement = $this->databaseEngine->prepare($sql);
     $value = $object->getUniqueReferenceValue();
     $statement->bindParam(':unique_reference', $value, 'int' == $this->uniqueReferenceFieldType ? \PDO::PARAM_INT : \PDO::PARAM_STR);
     $statement->execute();
     if (1 !== $statement->rowCount()) {
         throw new \OutOfBoundsException("Record in table '{$this->table}' with reference of '{$value}' was not found in the database when toggling the " . $field_name . " field");
     }
 }
コード例 #2
0
ファイル: AbstractPdoDao.php プロジェクト: centralapps/core
 /**
  * Delete the model from the database
  * @param  ModelInterface        $model
  * @return void
  * @throws \OutOfBoundsException
  */
 public function delete(ModelInterface $object)
 {
     $sql = "DELETE FROM\n                    `{$this->tableName}`\n                WHERE\n                    `{$this->uniqueReferenceField}`=:unique_reference\n                LIMIT\n                    1";
     $statement = $this->databaseEngine->prepare($sql);
     $statement->bindParam(':unique_reference', $object->getUniqueReferenceValue(), 'int' == $this->uniqueReferenceFieldType ? \PDO::PARAM_INT : \PDO::PARAM_STR);
     $statement->execute();
     if (1 == $statement->rowCount()) {
         throw new \OutOfBoundsException("Record in table '{$this->tableName}' with reference of '{$object->getUniqueReferenceValue()}' was not found in the database when deleting");
     }
 }