如何在不修改它们的情况下获取所有CRUD Mysql查询的ID?

Let’s suppose we have a big legacy PHP project which uses direct SQL queries into a class named MysqlCls. Each http request gets routed to a dedicated controller. That controller will then ask a dedicated model class to do CRUD operations on the DB. There are a few hundred model classes that contain thousands of SQL statement strings inside themselves so I cannot change the actual SQLs. The MysqlCls class extends Mysqli and has methods that receive the SQL string and return the results either as an array or Mysqli. Every DB table has a primary key column named “id” (with auto increment).

My question is: Is it possible to get the all affected (selected) row IDs for all SQL queries. I know that when we do an insert - there is a “last insert id” so that answers the question for the “C” of “CRUD”. What about RUD?

What I am trying to build is a parser that can sit on top of the MysqlCls class (as a proxy for it). When a request comes in and the whole website gets generated - I would like that parser to hold a static array property with all the table IDs from all the queries used by PHP/Mysql to answer that http request.

So if index.php has 10 SELECT SQL queries – I would like to have a multidimensional array with 10 root keys. Each root key name will be the table’s name. Its value will be an array with all the IDs of that table that were used to answer that request.

I have figured out the INSERT part and how to get the table names. How can I do the rest without modifying any of the queries?

Please note: I can prepend or append to the SQL strings, but I cannot change what’s inside of them.

Many thanks