title: Check if the entry in DB exists - Drupal 7
body: <p>I have made a module that when cron run it gets the wid and variables and timestamp from the watchdog table and pass it in a new table blablabla. I want if a value with same variables exists in the blablabla table do not pass this value. Here follow my code:</p>
  
  <pre><code>function blablabla_cron() {
  
    // Begin building the query.
    $query = db_select('watchdog', 'th')
      -&gt;extend('PagerDefault')
      -&gt;orderBy('wid')
      -&gt;fields('th', array('wid', 'timestamp'))
      -&gt;limit(2000);
  
    // Fetch the result set.
    $result = $query -&gt; execute();
  
    // Loop through each item and add to $row.
    foreach ($result as $row) {
      blablabla_table($row);
    }
  }
  
  function error_log_jira_table($row) {
  
    $timestamp = $row -&gt; timestamp;
    $wid = $row -&gt; wid;
    $variables = $row -&gt; variables;
  
    $nid = db_insert('error_log_jira')
      -&gt;fields(array(
        'timestamp' =&gt; $timestamp,
        'wid' =&gt; $wid,
        'variables' =&gt; $variables
      ))
      -&gt;execute();
  }
  </code></pre>