MyBB Community Forums

Full Version: Modify SQL statements passed to $db->query() method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am writing a plugin where I may need to modify it to modify the SQL statement. I searched the database methods and hooks, but could not find anything that serves my purpose.

Any pointers?

Thanks.
In theory you could do that by replacing $db with your own class... i.e. a replacement for $db which overrides the query method with your own code before it's passed on to the original function.

In practice however, that's a really ugly way of doing things. And I thought my hijacking the database result objects in Google SEO was bad. Well, it is.

Try to avoid it if you can... why do you think you need it?
I needed it for:
  1. I have created a tags plugin where the user may search by tag. Since the tags are stored in a different table, I needed to join the two table while searching.
  2. Login by email - I needed to replace the field names.

Instead of replacing the who db class, it would be nice to add an additional custom hook in the db class file.
In both cases, you can take over the form entirely and then simply run your own search / login process (and there may be more suitable hooks in the existing routines). That is not a very nice solution either but it beats hooking into all and every SQL query any time.
Thanks, for now I am abandoned those ideas, and worked around instead. I will try and suggest the developers to include a hook for this too in the next release.

Thanks.