本文整理汇总了PHP中query::update方法的典型用法代码示例。如果您正苦于以下问题:PHP query::update方法的具体用法?PHP query::update怎么用?PHP query::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类query
的用法示例。
在下文中一共展示了query::update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Save the user instance in database
* @return Boolean true if successfully saved, false otherwise
*/
public function save()
{
// Si l'utilisateur existe, on le met à jour
if ($this->ok()) {
// Mise à jour de l'utilisateur
$user = new query();
$user->update('user');
foreach ($this->field as $key => $value) {
switch ($key) {
case "id":
case "login":
// On ne modifie jamais l'ID de l'utilisateur et on enregistre pas le temps de mise à jour de la session s'il y en a une.
break;
default:
// On modifie la ligne
$user->set($key, trim($value));
break;
}
}
$user->where('id', '=', $this->get('id'));
$user->exec();
//Mise à jour des options
foreach ($this->create as $create) {
$query = new query();
$query->insert('user_option')->set('key', $create)->set('value', $this->option[$create])->set('owner', $this->get('id'))->exec();
}
foreach ($this->change as $change) {
$query = new query();
$query->update('user_option')->set('value', $this->option[$change])->where('owner', '=', $this->get('id'))->where('key', '=', $change)->exec();
}
return true;
// Si l'utilisateur n'existe pas, impossible de le mettre à jour, on retourne une erreur.
} else {
$user = new query();
$user->insert('user')->set('username', $this->get('username'));
$id = $user->exec();
$this->set('id', $id);
$this->ok = true;
$this->save();
return true;
}
}
示例2: saveObject
/**
* Saves an instantiated object to its respective table as a record.
*
* @return boolean Whether or not object could be saved.
*/
public function saveObject ()
{
try
{
# Validation bit
$validate = new validate(metaclass::$db);
$validate->exec($this);
if (! $validate->valid)
{
$this->invalid = $validate->invalid;
return false;
} else
{
if (! metaclass::checkTable($this))
{
metaclass::createTable($this->table, $this->definitions);
}
if (janitor::notNull($this->id))
{
# Updating existing row, editing object.
foreach ($this->definitions as $k => $v)
{
$queryStatements[$k] = janitor::cleanData($this->properties[$k], 'sql');
}
$query = new query();
$query->update($this->table)->set($queryStatements)->where('id', janitor::cleanData($this->id));
if (! metaclass::$db->query($query))
{
return false;
}
} else
{
# Inserting new row, creating object.
foreach ($this->properties as $k => $v)
{
$queryFields[] = $k;
$queryData[] = janitor::cleanData($v, 'sql');
}
$query = new query();
$query->insert($this->table, $queryFields)->values($queryData);
if (! metaclass::$db->query($query))
{
return false;
}
}
return true;
}
} catch (Exception $e)
{
trigger_error($e->getMessage(), E_USER_ERROR);
}
}