Last active
August 29, 2015 14:08
-
-
Save absent1706/5e64b86d9711d62cb55b to your computer and use it in GitHub Desktop.
Magento: insert or update (if already exists) row in DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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