数据库更改时启动PHP文件?

I have a database that has 20 rows each row I had set a Boolean value to it, so it is by default zero and when a row gets viewed its value changes to 1

I want the database to send any kind of signal that when 10 rows their value change from zero to 1, a certain PHP file fires up and starts a process that will affect only these 10 rows
How can I do that?

Thanks in advance

I would say, query from the php file every set amount of time to your database

The other way, database to execute a php file is almost impossible.

If you are using mySQL as database, a trigger could invoke the sys_exec() UDF available here: https://github.com/mysqludf/lib_mysqludf_sys#readme

So, there might be a possibility, actually, via an UDF function that would launch the php executable/script; not that easy, but seems possible ;-)

Invoking php from mysql is impossible, all you can do is set cron jobs for it. Cron job check mysql after certain interval of time and run the respected code

Every database is only a storage and it is its purpose in the system. Don't try to trigger any external process by the storage. The communication with the storage should be only a one way.

Rather think how to trigger your process from outside. Generally, there are two approaches:

  • a script that will check your database data in some interval like 1s, 10s, 1min or whatever would fit for a particular process
  • the current process that is updating your data can check your data and trigger another process if needed.

You can not trigger external file/script from mysql. What you can do is create a cron job which run after certain interval of time which check database and perform certain operations.