本文整理汇总了PHP中Doctrine\DBAL\Connection::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::update方法的具体用法?PHP Connection::update怎么用?PHP Connection::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Saves the pool to the database.
*
* @param \MusicBox\Entity\Like $pool
*/
public function save($pool)
{
$poolData = array('address_id' => $pool->getAddress()->getId(), 'access_info' => $pool->getAccessInfo());
if ($pool->getId()) {
$this->db->update('pools', $poolData, array('pool_id' => $pool->getId()));
$newFile = $this->handleFileUpload($item);
if ($newFile) {
$poolData['image'] = $pool->getImage();
}
} else {
// The pool is new, note the creation timestamp.
$poolData['created_at'] = time();
$this->db->insert('pools', $poolData);
// Get the id of the newly created pool and set it on the entity.
$id = $this->db->lastInsertId();
$pool->setId($id);
// If a new image was uploaded, update the pool with the new
// filename.
$newFile = $this->handleFileUpload($pool);
if ($newFile) {
$newData = array('image' => $pool->getImage());
$this->db->update('pools', $newData, array('pool_id' => $id));
}
}
}
示例2: save
/**
* Saves the artist to the database.
*
* @param \MusicBox\Entity\Artist $artist
*/
public function save($artist)
{
$artistData = array('name' => $artist->getName(), 'short_biography' => $artist->getShortBiography(), 'biography' => $artist->getBiography(), 'soundcloud_url' => $artist->getSoundCloudUrl(), 'image' => $artist->getImage());
if ($artist->getId()) {
// If a new image was uploaded, make sure the filename gets set.
$newFile = $this->handleFileUpload($artist);
if ($newFile) {
$artistData['image'] = $artist->getImage();
}
$this->db->update('artists', $artistData, array('artist_id' => $artist->getId()));
} else {
// The artist is new, note the creation timestamp.
$artistData['created_at'] = time();
$this->db->insert('artists', $artistData);
// Get the id of the newly created artist and set it on the entity.
$id = $this->db->lastInsertId();
$artist->setId($id);
// If a new image was uploaded, update the artist with the new
// filename.
$newFile = $this->handleFileUpload($artist);
if ($newFile) {
$newData = array('image' => $artist->getImage());
$this->db->update('artists', $newData, array('artist_id' => $id));
}
}
}
示例3: update
public function update($id, CacheRecord $cacheRecord)
{
$count = $this->db->update($this->entityTable, $cacheRecord->toArray(), array("id" => $id));
if ($count <= 0) {
throw new InvalidArgumentException("The update failed.");
}
}
示例4: restorePortfolioTitle
public function restorePortfolioTitle()
{
$totalPortfolioProcessed = 0;
$nbPortfolioProcessed = 0;
if ($this->connection->getSchemaManager()->tablesExist(array('icap__portfolio_widget_title'))) {
$this->log('Restoring portfolio titles...');
$rowPortfolioTitles = $this->connection->query('SELECT * FROM icap__portfolio_widget_title');
$sql = 'SELECT aw.id, aw.user_id FROM icap__portfolio_abstract_widget aw WHERE id = :id';
$stmt = $this->connection->prepare($sql);
foreach ($rowPortfolioTitles as $rowPortfolioTitle) {
$stmt->bindValue('id', $rowPortfolioTitle['id']);
$stmt->execute();
foreach ($stmt->fetchAll() as $rowAbstractWidget) {
$this->connection->update('icap__portfolio', ['title' => $rowPortfolioTitle['title'], 'slug' => $rowPortfolioTitle['slug']], ['id' => $rowAbstractWidget['user_id']]);
}
$this->connection->delete('icap__portfolio_abstract_widget', ['id' => $rowPortfolioTitle['id']]);
++$nbPortfolioProcessed;
if ($nbPortfolioProcessed >= 10) {
$totalPortfolioProcessed += $nbPortfolioProcessed;
$nbPortfolioProcessed = 0;
$this->log(' processing portfolio...');
}
}
$this->log(sprintf(' %d portfolio processed', $totalPortfolioProcessed + $nbPortfolioProcessed));
$this->connection->delete('icap__portfolio_widget_type', ['name' => 'title']);
$this->connection->getSchemaManager()->dropTable('icap__portfolio_widget_title');
}
}
示例5: save
/**
* Saves the user to the database.
*
* @param \MusicBox\Entity\User $user
*/
public function save($user)
{
$userData = array('username' => $user->getUsername(), 'mail' => $user->getMail(), 'role' => $user->getRole());
// If the password was changed, re-encrypt it.
if (strlen($user->getPassword()) != 88) {
$userData['salt'] = uniqid(mt_rand());
$userData['password'] = $this->encoder->encodePassword($user->getPassword(), $userData['salt']);
}
if ($user->getId()) {
// If a new image was uploaded, make sure the filename gets set.
$newFile = $this->handleFileUpload($user);
if ($newFile) {
$userData['image'] = $user->getImage();
}
$this->db->update('users', $userData, array('user_id' => $user->getId()));
} else {
// The user is new, note the creation timestamp.
$userData['created_at'] = time();
$this->db->insert('users', $userData);
// Get the id of the newly created user and set it on the entity.
$id = $this->db->lastInsertId();
$user->setId($id);
// If a new image was uploaded, update the user with the new
// filename.
$newFile = $this->handleFileUpload($user);
if ($newFile) {
$newData = array('image' => $user->getImage());
$this->db->update('users', $newData, array('user_id' => $id));
}
}
}
示例6: editLastLoginIp
public function editLastLoginIp($admin)
{
$data = array();
$lastLoginIp = $admin->getLastLoginIp();
$data['lastLoginIp'] = $lastLoginIp;
$result = $this->db->update('admin', $data, array('id' => $admin->getId()));
return $result;
}
示例7: updateUsername
private function updateUsername(ChangedUsername $payload)
{
$identifier = ['userIdentifier' => $payload->userIdentifier()->toString()];
$data = [];
$data['username'] = $payload->newUsername()->toString();
$data['at'] = $payload->at()->format('Y-m-d H:i:s');
$this->connection->update($this->table, $data, $identifier);
}
示例8: save
/**
* {@inheritdoc}
*/
public function save(Album $album)
{
$data = $album->getArrayCopy();
if (null === $album->getId()) {
return $this->db->insert('album', $data);
} else {
return $this->db->update('album', ['artist' => $data['artist'], 'title' => $data['title']], ['id' => $data['id']]);
}
}
示例9: save
/**
* @param Album $album
* @param int $id
* @return int The number of affected rows
*/
public function save(Album $album, $id = null)
{
$data = $album->getArrayCopy();
if (null === $id) {
return $this->db->insert('album', $data);
} else {
return $this->db->update('album', $data, ['id' => $id]);
}
}
示例10: save
/**
* @param PublishedPost $publishedPost
*
* @return void
*/
public function save(PublishedPost $publishedPost)
{
$data = ['title' => $publishedPost->title, 'content' => $publishedPost->content, 'category' => $publishedPost->category];
try {
$this->connection->insert('published_posts', array_merge($data, ['id' => $publishedPost->id]));
} catch (\Doctrine\DBAL\DBALException $e) {
$this->connection->update('published_posts', $data, ['id' => $publishedPost->id]);
}
}
示例11: set
/**
* Sets an item in the store.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public function set($key, $value)
{
if ($this->exists($key)) {
$this->db->update('configurations', ['value' => $value], ['code' => $key]);
return;
}
// Insert it
$this->db->insert('configurations', ['code' => $key, 'value' => $value]);
}
示例12: cacheSearchResult
/**
* @param string $location
* @param array $data
*/
public function cacheSearchResult($location, $data)
{
$qb = $this->db->createQueryBuilder()->select('*')->from('search_cache', 's')->where('s.location = :location')->setParameter('location', strtolower($location))->execute();
if (count($qb->fetchAll()) === 0) {
$this->db->insert('search_cache', ['location' => strtolower($location), 'cache' => serialize($data), 'time' => date('Y-m-d H:i:s')]);
return;
}
$this->db->update('search_cache', ['cache' => serialize($data), 'time' => date('Y-m-d H:i:s')], ['location' => strtolower($location)]);
}
示例13: update
/**
* Executes an SQL UPDATE statement on a table.
*
* @param array $data An associative array containing column-value pairs.
* @param array $identifier The update criteria. An associative array containing column-value pairs.
* @return integer The number of affected rows.
*/
public function update(array $data, array $identifier)
{
if (array_key_exists($this->createdAtRowName, $data)) {
unset($data[$this->createdAtRowName]);
}
if (!array_key_exists($this->updatedAtRowName, $data)) {
$data[$this->updatedAtRowName] = $this->now->format($this->dateFormat);
}
return $this->conn->update($this->getTableName(), $data, $identifier);
}
示例14: save
/**
* Saves the restaurant to the database.
*
* @param Restaurant $restaurant
*
* @return Restaurant $restaurant
*/
public function save($restaurant)
{
$restaurantData = array('nom' => $restaurant->getNom(), 'adresse' => $restaurant->getAdresse(), 'cp' => $restaurant->getCp(), 'ville' => $restaurant->getVille(), 'ouverture' => $restaurant->getOuverture(), 'fermeture' => $restaurant->getFermeture(), 'likes' => $restaurant->getLikes());
if ($restaurant->getId()) {
$this->db->update('restaurants', $restaurantData, array('id' => $restaurant->getId()));
} else {
$this->db->insert('restaurants', $restaurantData);
$last = $this->db->lastInsertId();
return $this->find($last);
}
}
示例15: save
/**
* Saves the produit to the database.
*
* @param Produit $produit
*
* @return Produit $produit
*/
public function save($produit)
{
$produitData = array('nom' => $produit->getNom(), 'prix' => $produit->getPrix(), 'type' => $produit->getType(), 'image' => $produit->getImage(), 'restaurant' => $produit->getRestaurant());
if ($produit->getId()) {
$this->db->update('produits', $produitData, array('id' => $produit->getId()));
} else {
$this->db->insert('produits', $produitData);
$last = $this->db->lastInsertId();
return $this->find($last);
}
}