MyBB Community Forums
[For 1.8] Database Helper - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Releases (https://community.mybb.com/forum-102.html)
+---- Thread: [For 1.8] Database Helper (/thread-215843.html)



Database Helper - dragonexpert - 2018-02-09

Plugin Name: Database Helper
Latest Version: 2.0
Uses Language: Yes
Languages Available: English
Download: https://community.mybb.com/mods.php?action=view&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->.


RE: Database Helper - dragonexpert - 2018-02-13

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.


RE: Database Helper - Omar G. - 2018-02-17

It would be perfect if it would log front end error messages as well.


RE: Database Helper - .m. - 2018-02-17

^ would you suggest merging of Error Viewer plugin code with this ?


RE: Database Helper - Omar G. - 2018-02-17

Pretty much, yes .m.