Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mysql

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?

like image 792
ionFish Avatar asked Jun 26 '26 10:06

ionFish


1 Answers

I would recommend against it. One of the disadvantages is that the code can not be cached by an op-code cache like e.g. APC. Furthermore it is not that easy to manage the code in a version control system. And later on when you want to have unit tests, continuous integration tests etc. it will be a lot more cumbersome too.

like image 200
Raffael Luthiger Avatar answered Jun 29 '26 00:06

Raffael Luthiger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!