Esempio n. 1
0
 /**
  * 
  * @param PCMapper $mapper
  * @param array $keys
  * @param string $conditions
  * @param array $bindings
  * @return boolean
  */
 public static function updateObject($mapper, $keys, $conditions, $bindings = array())
 {
     if (isset($conditions) == FALSE) {
         throw new PCException("InternalInconsistency", 500);
     }
     $table_name = $mapper->getTableForInsertUpdate();
     if (isset($keys['identifier'])) {
         PCCache::cacheProvider()->removeItem($mapper->getCacheKey($keys));
     }
     $update = "UPDATE {$table_name} SET ";
     $prepared_keys = array();
     $first = TRUE;
     foreach ($keys as $key => $value) {
         $placeHolder = ':' . $key;
         if ($first) {
             $first = FALSE;
             $update .= " {$key} =  {$placeHolder} ";
         } else {
             $update .= ", {$key} =  {$placeHolder} ";
         }
         $prepared_keys[$placeHolder] = $value;
     }
     $update .= " WHERE {$conditions}";
     $pdo = PCDatabase::getSharedDatabaseConnection();
     $prepared = $pdo->prepare($update);
     if ($prepared === FALSE) {
         c_dump($prepared->errorInfo());
         return FALSE;
     }
     $merged = array_merge($bindings, $prepared_keys);
     $result = $prepared->execute($merged);
     if ($result === FALSE) {
         c_dump($prepared->errorInfo());
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 2
0
 /**
  * 
  * @param PCMapper $mapper
  * @param array $values
  * @param PCDatabaseQueryCondition $condition
  * @return PCDatabaseUpdateQuery
  */
 public static function withMapper($mapper, $values, $condition = NULL) {
     return new PCDatabaseUpdateQuery($mapper->getTableForInsertUpdate(), $values, $condition);
 }