Php 删除具有最早时间戳的值
我想在cron运行时删除最早的timestamp值,同时创建新的timestamp值。我有cron的代码。在此处,从watchdog中选择所有值:Php 删除具有最早时间戳的值,php,mysql,drupal,drupal-7,cron,Php,Mysql,Drupal,Drupal 7,Cron,我想在cron运行时删除最早的timestamp值,同时创建新的timestamp值。我有cron的代码。在此处,从watchdog中选择所有值: function error_cron() { // Begin building the query. $query = db_select('watchdog', 'th') ->extend('PagerDefault') ->orderBy('wid') ->fields('th', array('variab
function error_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.
foreach ($result as $row) {
error_table($row);
}
在下一段代码中,我在表中创建了看门狗的不同值:
function error_table($row) {
$variables = $row -> variables;
$timestamp = $row -> timestamp;
$wid = $row -> wid;
$r = db_select('error', 'b')
-> fields('b')
-> condition('variables', $variables, '=')
-> condition('timestamp', $timestamp, '<=')
-> execute();
if($r -> rowCount() == 0) {
$query = db_insert('error')
->fields(array(
'timestamp' => $timestamp,
'wid' => $wid,
'variables' => $variables,
))
->execute();
}
}
函数错误\u表($row){
$variables=$row->variables;
$timestamp=$row->timestamp;
$wid=$row->wid;
$r=db\u选择('error','b')
->字段('b')
->条件('variables',$variables',=')
->条件('timestamp',$timestamp',我用这行代码解决了我的问题:
$giannis = db_delete('error')
-> condition('variables', $variables, '=')
-> condition('timestamp', $timestamp, '<')
->execute();
$giannis=db_delete('error'))
->条件('variables',$variables',=')
->条件('timestamp',$timestamp','