我想要的是检查变量=变量和时间戳>时间戳,如果这是真的删除旧值并创建新的我认为上面的代码只是创建所有值,因为它不会删除旧值。在创建新文件时如何删除旧文件?
$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.
foreach ($result as $row) {
blabla($row);
}
function blabla($row)
$timestamp = $row -> timestamp;
$r = db_select('distinct', 'b')
->fields('b')
->condition('variables', $variables, '=')
->condition('timestamp', $timestamp, '>')
->execute();
if($r -> rowCount() == 0) {
$query = db_delete('error_log_jira')
->fields('b', array('timestamp', 'wid', 'variables',))
->execute();
$query = db_insert('distinct')
->fields(array(
'timestamp' => $timestamp,
'wid' => $wid,
'variables' => $variables,
))
->execute();
}
此代码完美无缺
$r = db_select('blabla', 'b')
->fields('b')
->condition('variables', $variables, '=')
->execute();
答案 0 :(得分:0)
您在代码示例中使用<
(低于)代替>
(大于)。
$r = db_select('blabla', 'b')
->fields('b')
->condition('variables', $variables, '=')
->condition('timestamp', $timestamp, '>')
->execute();
如果要调试并查看执行的查询,可以使用dpq()
函数(devel模块的一部分):https://api.drupal.org/api/devel/devel.module/function/dpq/7