Skip to content

Instantly share code, notes, and snippets.

@absent1706
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save absent1706/5e64b86d9711d62cb55b to your computer and use it in GitHub Desktop.
Save absent1706/5e64b86d9711d62cb55b to your computer and use it in GitHub Desktop.
Magento: insert or update (if already exists) row in DB
protected function _insertOrUpdateData(&$dbAdapter, $table, $data, $where)
{
$select = $dbAdapter->select()->from($table);
foreach ($where as $condition => $value)
{
$select->where($condition, $value);
}
if ($dbAdapter->fetchOne($select))
{
$dbAdapter->update($table, $data, $where);
}
else
{
$dbAdapter->insert($table, $data, $where);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment