/**
  * Commit a transaction
  * 
  * This function will commit a transaction.
  * 
  * @return bool True on success, exception thrown on failure
  * 
  */
 public function commit()
 {
     $result = $this->conn->commit();
     if (DB::isError($result)) {
         throw new LoggedException($result->getMessage(), $result->getCode(), self::module);
     }
     $this->conn->autoCommit(true);
     return true;
 }
Example #2
0
 /**
  * Given a new attribute set and an id, insert each into the DB. If
  * anything fails in here, rollback the transaction, return the relevant
  * error and bail out.
  *
  * @param integer $id        The id of the record for which attributes are
  *                           being inserted.
  * @param array $attributes  An hash containing the attributes.
  */
 function insertAttributes($id, $attributes)
 {
     foreach ($attributes as $attr) {
         $query = 'INSERT INTO ' . $this->_params['attribute_table'] . ' (' . $this->_params['id_column'] . ', attribute_name,' . ' attribute_key, attribute_value) VALUES (?, ?, ?, ?)';
         $values = array((int) $id, $attr['name'], $attr['key'], $attr['value']);
         Horde::log('SQL Query by Hylax_SQL_Attributes::insertAttributes(): ' . $query, 'DEBUG');
         $result = $this->_db->query($query, $values);
         if (is_a($result, 'PEAR_Error')) {
             $this->_db->rollback();
             $this->_db->autoCommit(true);
             return $result;
         }
     }
     /* Commit the transaction, and turn autocommit back on. */
     $result = $this->_db->commit();
     $this->_db->autoCommit(true);
 }