データベースにはいつでもlast_import
列を追加できます。スクリプトがmysqlデータベースに何かをインポートするたびに、インポートする前に、のすべての値last_import
をnoまたは類似のものに変更し、yesまたは類似した値で行を入力します。この方法を使用すると、最後にインポートされたものを簡単に確認できます。
これがあなたのデータベースだとしましょう:
-----------------
| id | name |
-----------------
| 1 | Simon |
-----------------
| 2 | Richard|
-----------------
| 3 | Jon |
-----------------
このフィールドを追加します。
-------------------------------
| id | name | last_import |
-------------------------------
| 1 | Simon | N |
-------------------------------
| 2 | Richard| N |
-------------------------------
| 3 | Jon | N |
-------------------------------
したがって、mysqlを使用している場合(使用していない場合は教えてください)、データを挿入して処理するたびにこれを実行してください。
// Process data before here
$query = "UPDATE thetable SET last_import = 'N'"; // Changes all values of last_import in table to N
$result = @mysql_query($query) or die (mysql_error());
$query = "INSERT command here"; // do your inserting, while inserting the rows, put Y as the value of the last_import.
次に、最終チェックファイルで:
$query = "SELECT * FROM thetable WHERE last_import = 'Y'"; // Selects all that was last imported
// Process the query here
それはうまくいくはずです。
更新: Gavinの提案に感謝します(Gavinに感謝します!)タイムスタンプ値を使用することも提案します。これは次のように機能します。
テーブルは次のようになります。
-------------------------------
| id | name | last_import |
-------------------------------
| 1 | Simon | 1346748315 |
-------------------------------
| 2 | Richard| 1346748315 |
-------------------------------
| 3 | Jon | 1346748315 |
-------------------------------
そしてあなたの挿入クエリで:
// Process data before here
$currenttimestamp = time();
$query = "INSERT command here"; // do your inserting, while inserting the rows, put $currenttimestamp as the value of the last_import.
そして選択するとき:
$query = "SELECT last_import FROM thetable ORDER BY last_import DESC LIMIT 1"; // Selects the most recent timestamp
$result = @mysql_query($query) or die (mysql_error());
$mostrecenttstmp = @mysql_result($result, 0);
$query = "SELECT * FROM thetable WHERE last_import = '$mostrecenttstmp'";
// Process the query here