Created
October 11, 2011 16:29
-
-
Save johnrobertwilson/1278603 to your computer and use it in GitHub Desktop.
db query example
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
/** | |
* 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