<?php
if (!$con = mysql_connect('localhost', 'root', 'password')) {
die('An error occurred while connecting to the MySQL server!<br><br>' .
mysql_error());
}
if (!mysql_select_db('mydb')) { die('An error occurred while connecting
to the database!<br><br>' . mysql_error()); }
// Create an array of MySQL queries to run
$sql = array( 'DROP TABLE IF EXISTS appengage.updateon;', 'CREATE TABLE
appengage.updateon SELECT start_date, updated_on FROM mydb.issues
WHERE start_date BETWEEN DATE_SUB(NOW(), INTERVAL 3 Day) AND NOW();'
);
// Run the MySQL queries
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!mysql_query($query)) {
die('A MySQL error has occurred!<br><br>' . mysql_error());
}
}
}
?>
以上代码给出了在过去3天内更新过的记录,但我希望这些记录在过去3天内未更新。
答案 0 :(得分:0)
通过这种方式更改代码:
// Create an array of MySQL queries to run
$sql = array( 'DROP TABLE IF EXISTS appengage.updateon;', 'CREATE TABLE
appengage.updateon SELECT start_date, updated_on FROM mydb.issues
WHERE start_date NOT BETWEEN DATE_SUB(NOW(), INTERVAL 3 Day) AND NOW();'
);
我在NOT
BETWEEN DATE_SUB