Search code examples
phpmysqldatabasedrupaldrupal-7

I cannot create values in my table


I have this code that takes the values of a watchdog table when cron runs and i want to get the wid and timestamp and pass it in my table with name blablabla:

function blablabla_cron() {

  // Begin building the query.
  $query = db_select('watchdog', 'th')
    ->extend('PagerDefault')
    ->orderBy('wid')
    ->fields('th', array('variables', 'type', 'severity', 'message', 'wid', 'timestamp'))
    ->limit(2000);

  // Fetch the result set.
  $result = $query -> execute();

  // Loop through each item and add to $row.
  $already_processed = array();
  foreach ($result as $row) {
    $unique_value = unserialize($row -> variables);
    if (in_array($unique_value, $already_processed)) 
      continue;
      $already_processed[] = $unique_value;
      blablabla_table($row);
  }
}

function blablabla_table($row) {

  $timestamp = $row -> timestamp;
  $wid = $row -> wid;
  $num_updated = db_update('blablabla') 
  ->fields(array(
    'wid' => $wid,
    'timestamp' => $timestamp,
  ))
  ->condition('created', REQUEST_TIME - 3600, '>=')
  ->execute();
}

I cannot understand where in the code is my fault as the table is still empty :( :(


Solution

  • I solve my problem in the blablabla_table function i get:

    function blablabla_table($row) {
    
      $timestamp = $row -> timestamp;
      $wid = $row -> wid;
      $nid = db_insert('error_log_jira')
        ->fields(array(
          'timestamp' => $timestamp,
          'wid' => $wid,
        ))
        ->execute();
    }