Skip to content

Instantly share code, notes, and snippets.

@johnrobertwilson
Created October 11, 2011 16:29
Show Gist options
  • Save johnrobertwilson/1278603 to your computer and use it in GitHub Desktop.
Save johnrobertwilson/1278603 to your computer and use it in GitHub Desktop.
db query example
/**
* socialflow_record_history
*/
function socialflow_record_history($entity_type, $bundle, $entity_id) {
//check to see if the record exists
$check_query = db_query(
'SELECT count(entity_id)
FROM socialflow_history
WHERE entity_type = :entity_type
AND bundle = :bundle
AND entity_id = :entity_id',
array(':entity_type' => $entity_type,
':bundle' => $bundle,
':entity_id' => $entity_id));
$check_results = $check_query->fetchField();
if(!empty($check_results)) {
//Update
$fields = array('resubmitted' => REQUEST_TIME);
db_update('socialflow_history')
->fields($fields)
->condition('entity_type', $entity_type)
->condition('entity_id', $entity_id)
->condition('bundle', $bundle)
->execute();
} else {
//Insert
$fields = array('entity_id' => $entity_id, 'entity_type' => $entity_type, 'bundle' => $bundle, 'submitted' => REQUEST_TIME);
db_insert('socialflow_history')->fields($fields)->execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment