Doubts to query the mysql bank?

0

Is there a way to create a code to check if a new record exists in the database?

EX: I've inserted id = 2, I need to create a code that will generate a notification every time a new id pops up.

    
asked by anonymous 09.03.2017 / 23:57

2 answers

1

You can create a trigger before insert, and in the trigger do what you want! because this trigger will be triggered whenever an insert will happen

    
10.03.2017 / 01:45
1

For those who do not know what Trigger (or me) is, what you can do is:

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

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

2) - At the next check you take the total records from the database and compare them with the value of the text file. Ex:

SELECT SUM(column_name) FROM table_name;

with

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

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

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

"Check for new records" is not easy !! It is not enough just to count them if they support DELETEs. That's another story.

Another alternative is to have an insert or delete your code trigger a mail to your mailbox.

    
10.03.2017 / 02:41