0

I'm trying to revamp a product . Actually the old web app was written in raw php . Now the new one is supposed to be written in MERN stack . Now the problem is i want to know upon a certain action from my frontend which tables got hit (insert,update,select) in the database from my php code . Is the a way to do this with actually reading the whole code ?

Shadow
  • 33,525
  • 10
  • 51
  • 64
Moaz Maalik
  • 27
  • 1
  • 5
  • 1
    question unclear, are you trying to say you have a laravel backend that the mern app sending request to? – shababhsiddique Jun 06 '22 at 12:35
  • no its a raw php web app . Has nothing to do with MERN app . We are trying to built the app again but in MERN stack . Basically we are trying to replicate it in MERN . – Moaz Maalik Jun 06 '22 at 12:44
  • your question is rather unclear, based on your description *"old web app was written in raw php"* thats not what laravel is. that being said, you can either log queries on mysql as per issac's answer or you can use [laravel query log](https://stackoverflow.com/questions/41140975/laravel-eloquent-display-query-log) if you are actually using laravel. – Bagus Tesa Jun 06 '22 at 13:06
  • not using laravel . I've mentioned raw php – Moaz Maalik Jun 06 '22 at 13:14

1 Answers1

0

You should set some mysql global variables as explained in this useful threat : How to enable MySQL Query Log?

How it works ?

Go to mysql/mariadb console and type the following :

SET GLOBAL general_log = 1;
SET GLOBAL log_output = 'table';

Theses lines allow the logs on every request you make since activation.

To check the logs, go to mysql database by using :

use mysql

Then, check the logs with :

select * from general_log

It will show you :

  1. Date
  2. User who performed the request
  3. The whole request

You could use this system to get requests you need by using filters.

Note : Depending on what framework you are using with PHP, you could use post-request triggers, check frameworks like https://symfony.com/ for more informations.

Note 2 : Please explain your problem with a bit more clarity.

EDIT :

Just providing a visual example of what this table looks like :

Example of general_log output

Issac411
  • 54
  • 4
  • The problems is i want to study a certain module in our web app .For instance there is a Clients module in out web app . It has features such as Create client , edit client , view client . Now if we want to rewrite the complete app from scratch in node but with the database we need to know the upon what action does a certain table gets queried in the database . Lets say create client feature gets some details from table A , updates some data in table B and inserts some data in table C . Now to know which tables were involved i can read the code for create client . But is there any other way? – Moaz Maalik Jun 06 '22 at 12:54
  • So, you want to get all tables called by a php function ? I dont get it. If you want to test what tables are called by a function, activate the logs as i explained and then call your function. The requests will all be added to the general_log table. I edited my response by adding an example pic of general_log output. – Issac411 Jun 06 '22 at 12:58
  • 1
    at the moment when i run the command SET GLOBAL general_log = 1 . I get the error "Access denied; you need (at least one of) the SUPER privilege(s) for this operation". I need to contact the devops person for the access . If i start getting entries in this table . after i'm done with my work . Will there be a way to reset it back to normal ? – Moaz Maalik Jun 06 '22 at 13:03
  • Yes and yes. The variables modification is a super-admin process, you have to use the mysql console from the server. Ask your devops to do the changes. You can reverse it by setting the variables to 0 and deleting general_log data. (by using a query like "delete from mysql.general_log") – Issac411 Jun 06 '22 at 13:07
  • 1
    Got it . Thanks a lot . will let you know once i get the access – Moaz Maalik Jun 06 '22 at 13:11
  • 1
    You really should not enable mysql's general log on a production server, it has a significant performance impact on a busy server, not to mention the growth of the log file. – Shadow Jun 06 '22 at 14:45
  • As Shadow said, the general_log shouldn't be used in production, its mentioned on the link i posted in my answer. Thanks for the reminder comment. – Issac411 Jun 07 '22 at 06:48