Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created January 26, 2013 00:41
Show Gist options
  • Save cam-gists/4639247 to your computer and use it in GitHub Desktop.
Save cam-gists/4639247 to your computer and use it in GitHub Desktop.
PHP : Short Active Record
public function updateOrder($data = array())
{
$sql = 'UPDATE `user` SET ';
foreach ($data as $key => $value) {
if(is_numeric($value)){
$sql .= "`$key` = $value,";
}else{
$sql .= "`$key` = '$value',";
}
}
$sql = substr($sql, 0, -1);
$sql .= ' WHERE id = ?';
$sth = $this->dbh->prepare($sql);
$sth->execute(array($this->id));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment