Do you doubt the mysql database query?

Asked

Viewed 103 times

0

How to create a code to check if there is a new record in the database?

EX: id = 2 has been entered, I need to create a code that will generate a notification every time a new id appears.

  • One way would be to store the last id and then check if there is a id greater.

  • How would you do that?

  • "from my code check if there is a new data" I believe this needs to be better explained , but the link goes through Trigger , Event or something similar.

2 answers

3


You can create a Trigger before Insert, and at Trigger do what you want! because this Rigger will be triggered whenever an insertion will happen

2

For those who don’t know what Trigger is (like me), what you can do is:

1} - Store the amount of database records (select sum) you last checked in a text file. Ex:

file_put_contents("quant.txt",$quant);

2) - In the next check you take the total of records from the database and compare it to the value of the text file. Ex:

SELECT SUM(column_name) FROM table_name;

with

$content = file_get_contents('quant.txt');

3) - If there is a change create something to warn you (floating window, alert or whatever you want to do in this sense) and update your text file

file_put_contents('quant.txt', $novaQuant);

"Checking for new records" is not easy!! It is not enough to just tell them if they support Deletes. There is another story.

Another alternative is every time there is an Insert or delete your code shoot an email to your email box.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.