PHP Code (modules) included via MySQL database, good idea?

Posted by ionFish on Pro Webmasters See other posts from Pro Webmasters or by ionFish
Published on 2012-07-10T00:39:35Z Indexed on 2012/07/10 9:22 UTC
Read the original article Hit count: 204

Filed under:
|

The main script includes "modules" which add functionality to it. Each module is set up like this:

<?php
//data collection stuff
//(...) approx 80 lines of code
//end data collection
$var1 = 'some data';
$var2 = 'more data';
$var3 = 'other data';
?>

Each module has the same exact variables, just the data collection is different.

I was wondering if it's a reasonable idea to store the module data in MySQL like this:

[database]
|_modules
  |_name
  |_function (the raw PHP data from above)
  |_description
  |_author
  |_update-url
  |_version
  |_enabled

...and then include the PHP-data from the database and execute it? Something like, a tab-navigation system at the top of the page for each module name, then inside each of those tabs the page content would function by parsing the database-stored code of the module from the function section.

The purpose would be to save code space (fewer lines), allow for easy updates, and include/exclude modules based on the enabled option. This is how many other web-apps work, some of my own too. But never had I thought about this so deeply. Are there any drawbacks or security risks to this?

© Pro Webmasters or respective owner

Related posts about php

Related posts about mysql