Find from which file a sql query is running

Hello

I can see a query using SHOW PROCESSLIST and i am wondering if it is a way to know from which .php file is coming… ?

Any way to find it?

Thank you

Hi @syslogbeta and welcome to the forums.

Do you happen to know if the queries are written manually or through an ORM?
Which framework or library are you working with?
Which kind of data are you working with?

Also this may help:

SHOW FULL PROCESSLIST

Hello and thanks for your reply.

It is manual php code.

The SHOW FULL PROCESSLIST just give more details for the query but not from which php file is coming :frowning:

If you know the table name you could run a global search within your project directory and inspect the results. If there are too many try to see if you can search for more specific bits of the query… Are you using an IDE for programming? That should provide a global search function.

It’s not my code so i do not use any IDE…

At the moment i was thinking also to use the grep function and look around but i was ask if a more elegant way exist :slight_smile:

Thanks for your reply !

1 Like

If it’s code I’m working with I usually have all the files in an IDE or text editor and use the “find” feature to locate what files have the lines of code I’m looking for. A few times there was code I was curious about and rather than load them into a “project” used a recursive iterator script to display the files and lines.

I guess the information might possibly be in some kind of log file. I don’t know because the only log files I have spent any amount of time reading have been error logs, And even so, they are pretty much still like a foreign language to me. I don’t understand everything completely but I can usually recognize enough to get me pointed in the right direction.

If this is your own code you could add some kind of “tracker”. eg. in pseudo-code
run_query($args, $this_caller)
and keep $this_caller in a table.

It’s not my code but thanks for your recommendation !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.