How to check in real time if a new row has been added to a MySQL table

We have an auto plate reader that records car plates in a firm. My colleague asked me if we could immediately get the plate number of the car. The software uses MySQL, and I only have access to the database. Unable to reach / change PHP codes.

My suggestion is to periodically check the request. For example, within 10 seconds. But in this way you can skip cars coming in 5 seconds. Then a decreasing interval increases the number of requests / responses, which means additional load for the server. I do not want the script to run always. It should only run the newly added db line. He shows the plate and the exits.

How can I get the last recorded row from db right after insertion? I mean, after insertion, my PHP script should run. But I do not know.

I want MySQL to be able to run my PHP script after a new entry.

+4
source share
2 answers

MyISAM, . MyISAM . , MyISAM .

InnoDB . , car_table.id , SELECT COUNT(id) FROM car_table , . , :

ALTER car_table ADD COLUMN checked BOOLEAN NOT NULL DEFAULT 0, ADD INDEX (checked);

, 0 . :

BEGIN TRANSACTION; -- make sure nobody interferes
SELECT COUNT(checked) FROM car_table WHERE checked = FALSE FOR UPDATE; -- this gets you the number of new, unchecked cars
UPDATE car_table SET checked = TRUE WHERE checked = FALSE; -- mark these cars as checked
COMMIT;

, .

. , . TRUNCATE .

, UDF, Panagiotis, .

+2

, , script sys_exec() UDF , :

B.5.11: UDF?

. , sys_exec() UDF.

http://dev.mysql.com/doc/refman/5.1/en/faqs-triggers.html#qandaitem-B-5-1-11

, .

PHP script MySQL

0

All Articles