Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[For 1.8] Database Helper
#1
Plugin Name: Database Helper
Latest Version: 2.0
Uses Language: Yes
Languages Available: English
Download: https://community.mybb.com/mods.php?acti...w&pid=1083
Github: https://github.com/dragonexpert/database_helper

Installation:
1) Upload everything in the zip file to their respective directories.
2) Activate in the Admin CP.
3) View slow queries in Admin CP ->Tools & Maintenance -> Slow Query Log


Debugging:
If you have a page that is running slow, you might consider using search and replace to look for $db-> and change it to $db->helper-> in that file.  This will force any queries to go through the helper which will also log any query that takes longer than 2 seconds to execute.  You are then able to view the entry in the Admin CP and see how long it took for the query to execute.

Methods:
  • add_foreign_key - adds a foreign key. See function for parameters. Not supported in SQLite.
  • drop_foreign_key($name, $table) - Drops a foreign key.
  • get_foreign_keys - gets all foreign keys. ( Note only works on foreign keys created with add_foreign_key ).
  • count_query($table, $fields, $where) - performs a select count() and returns the result.
  • fetch_clean_array($resource, $resulttype = MYSQLI_ASSOC) - similar to fetch_array, but calls htmlspecialchars_uni on the result before returning it.
  • fetch_clean_field($resource, $field) - same as above except a field.
  • truncate_table($table) - Truncates a table.
  • setting_exists($setting) - Whether a setting exists.
  • log_slow_query($query, $execution_time) - Logs a query. Can be called manually if you provide the values.

Writing New Code:
The only difference you will need to make to your code is using $db->helper-> instead of just $db->.
Reply
#2
I have a new version on Github that needs testing. The new version also logs the value of the constant THIS_SCRIPT and the name of the file that generated the query. These improvements will make it faster to find the problem.
Reply
#3
It would be perfect if it would log front end error messages as well.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#4
^ would you suggest merging of Error Viewer plugin code with this ?
Reply
#5
Pretty much, yes .m.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)