Hi Rahim,
That is a tough issue! All database connections handled by WordPress are executed by the same database user. As a result you don’t have access to any user specific information when you execute a sql statement, which would be the simplest option.
You can add the WordPress user info to your requests, as you suggested, but you will need to add code in many different places. The plugin supports a number of hooks and filters that might allow you to add this functionality, but it doesn’t feel like the right thing to me.
I have been thinking about another alternative, which you might like a lot more. The plugin contains class WPDADB_WPDB, which inherits WordPress class wpdb. We could do some research and try to add a MySQL user defined variable that contains the WordPress user info. You would have access to that user defined variable in all your sql statements, including database triggers and procedures, eliminating the need to push the same data around in multiple code blocks.
I think this should be possible, but there is a limitation. Since WPDADB_WPDB inherits wpdb, this feature will be available for code that uses WPDADB_WPDB only. It will not work for local connections, which are using wpdb. It only works for remote databases. If your data is stored in a remote database, you won’t have to change anything. If your data is stored in your local WordPress database, you can create a remote loopback connection and use that connection in your WP Data Access applications.
What do you think?
I don’t have the time to do research right now. If you want to start on your own, please have a look at class WPDADB_WPDB->db_connect and try to add a user defined variable right after the connection was created. Here is the MySQL documentation:
https://dev.mysql.com/doc/refman/8.0/en/user-variables.html
Let me know…
Peter
Thread Starter
rladha
(@rladha)
Thanks, @peterschulznl
1. Let me look into to above suggestion. Currently, my app tables with missed with wordpress tables.
2. Is there a log table in WP which keeps track for every SQL execution by all plug-ins? Perhaps, I can use that?
Thanks again, let me dive deeper as this scenario is important for my application.
R
Thread Starter
rladha
(@rladha)
FYI: Using this plug-in, I am able to see the backend queries generated by WPDA… https://en-ca.wordpress.org/plugins/query-monitor/
I need to research if this data can be stored in the table, then it will solve my ask..
others have created further add-ons to this plug, perhaps, WPDA can also consider it… https://github.com/johnbillion/query-monitor/wiki/Query-Monitor-Add-on-Plugins
Hi Rahim,
I don’t know the Query Monitor plugin. From your requirements I understand that you want to be able to see the transactions per (WordPress) user. Is that correct? I don’t think this plugin supports user specific logs, but I’d be greatful if you could share your knowledge! 😊
Thanks,
Peter