mysql - PHP-function for querying out of the database -


i want have simple admin-script allows me disable or enable different modules of website, e.g. changelogs or news.

for have created datase table looks like:

+----+--------------+---------+ | id | function     | enabled | +----+--------------+---------+ | 1  | changelogs   | on      | | 2  | news         | off     | | .. | ..           | ..      |' +----+--------------+---------+ 

as said, want information whether module on or off php-function. did didn't work me.

functions.php:

$db = new mysqli("is correct", "is correct", "is correct", "is correct");  function function_enabled($function_module) {     if ($function_module == "changelogs") {         $sql = $db->query("select enabled functions function = '$function_module'");         while ($row = $sql->fetch_object()) {             $return = $row->enabled;         }         return "$return";     } } 

index.php

include("functions.php"); if(function_enabled("changelogs") == "on") {     echo'result or menu here...'; } 

do have idea?

$db doesn't exist within function_enabled function because of variable scope. need pass function, run new mysqli within function, make $db global variable or singleton, or otherwise make accessible within function.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -