DVigneault Posted July 6, 2012 Share Posted July 6, 2012 Hey all--new to web design (as will become clear very soon). I've been writing a website with numerous medical scoring systems, written in php. I thought that I would store the php scripts in a MySQL database and call them with eval(), until I saw the giant warning on php.net saying to never, ever, not ever, use eval(). Ever. Searching around, I find lots of references to storing php in MySQL databases as a "design flaw," but I haven't found guidelines about how else to do it. Should I be using include instead? Or something else? Best, ?Davis P.S. Sorry if there is already a post about this--whenever I try to search the site, I get an error saying that I don't have permission. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2012 Share Posted July 6, 2012 PHP scripts, being files, are normally stored in the filesystem. Is there some particular problem you're trying to solve by storing them in a database? Quote Link to comment Share on other sites More sharing options...
DVigneault Posted July 6, 2012 Author Share Posted July 6, 2012 Only that I thought it would be neater to store them in the database than having them in files. There are three scripts per calculator (which would mean three includes per page), and eventually hundreds of calculators (each calculator having its own page), and I thought there might be difficulties down the road in managing it this way. Is this common practice, to avoid using eval()? Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted July 6, 2012 Share Posted July 6, 2012 Listen, if you're basing your SQL queries on conditions, you could just as easily base your includes on conditions. There really is no logic to storing a script in the database if for no other reason except maintainability. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2012 Share Posted July 6, 2012 Generally, if your code uses eval(), you're doing it wrong. Why do you need hundreds of different scripts for calculators? There has to be a better/easier way. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2012 Share Posted July 6, 2012 There are three scripts per calculator (which would mean three includes per page), and eventually hundreds of calculators (each calculator having its own page) ^^^ That sounds like hard-coding values/data rather than using variables/functions.... If you post an example showing what your code is doing and what exactly is different between these various 'calculators' (show two different ones), someone can suggest a general purpose method that does not involve the evil (the name it should have been given) statement. Quote Link to comment Share on other sites More sharing options...
DVigneault Posted July 6, 2012 Author Share Posted July 6, 2012 @Mahngiel--you're right, I could use the same logic for includes. Seems that there is no reason not to use includes. Just that I didn't know that there was a reason not to use eval() when I wrote it, so I thought it would be good to ask before rewriting. :-) @Pikachu2000 and @PFMaBiSmAd--they are medical scoring systems/algorithms. Each one is separate/distinct. Two simple examples. APGAR //Function function calculate($a,$b,$c,$d,$e) { $result = ($a+$b+$c+$d+$e); echo "APGAR: " . $result . "<br>"; if ($result < 5) $range = "The child requires immediate assistance."; elseif ($result < $range = "The child requires assistance."; else $range = "The child is normal."; echo "Interpretation: " . $range; } //Form <form name="form" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Appearance:</legend> <label for="a1"> <input type="radio" name="a" id="a1" value="0" tabindex="1" <?php echo $a1; ?> /> Pale or Blue</label><br> <label for="a2"> <input type="radio" name="a" id="a2" value="1" tabindex="1" <?php echo $a2; ?> /> Blue in Extremities</label><br> <label for="a3"> <input type="radio" name="a" id="a3" value="2" tabindex="1" <?php echo $a3; ?> /> Pink</label> </fieldset> <fieldset> <legend>Pulse:</legend> <label for="b1"> <input type="radio" name="b" id="b1" value="0" tabindex="2" <?php echo $b1; ?> /> Absent</label><br> <label for="b2"> <input type="radio" name="b" id="b2" value="1" tabindex="2" <?php echo $b2; ?> /> Less than 100bpm</label><br> <label for="b3"> <input type="radio" name="b" id="b3" value="2" tabindex="2" <?php echo $b3; ?> /> Greater than 100bpm</label> </fieldset> <fieldset> <legend>Grimace:</legend> <label for="c1"> <input type="radio" name="c" id="c1" value="0" tabindex="3" <?php echo $c1; ?> /> No response</label><br> <label for="c2"> <input type="radio" name="c" id="c2" value="1" tabindex="3" <?php echo $c2; ?> /> Grimace</label><br> <label for="c3"> <input type="radio" name="c" id="c3" value="2" tabindex="3" <?php echo $c3; ?> /> Cough or Sneeze</label> </fieldset> <fieldset> <legend>Activity:</legend> <label for="d1"> <input type="radio" name="d" id="d1" value="0" tabindex="4" <?php echo $d1; ?> /> Flaccid</label><br> <label for="d2"> <input type="radio" name="d" id="d2" value="1" tabindex="4" <?php echo $d2; ?> /> Some Flexion</label><br> <label for="d3"> <input type="radio" name="d" id="d3" value="2" tabindex="4" <?php echo $d3; ?> /> Well Flexed</label> </fieldset> <fieldset> <legend>Respiration:</legend> <label for="e1"> <input type="radio" name="e" id="e1" value="0" tabindex="5" <?php echo $e1; ?> /> Absent</label><br> <label for="e2"> <input type="radio" name="e" id="e2" value="1" tabindex="5" <?php echo $e2; ?> /> Weak Cry</label><br> <label for="e3"> <input type="radio" name="e" id="e3" value="2" tabindex="5" <?php echo $e3; ?> /> Strong Cry</label> </fieldset> <input type="hidden" name="abbreviation" value="APGAR"> <input type="submit" name="submit" value="Calculate" tabindex="6"> </form> //Result calculate($_GET["a"],$_GET["b"],$_GET["c"],$_GET["d"],$_GET["e"]); Anion Gap: //Function function calculate($sodium,$potassium,$chloride,$bicarbonate) { $result = ($sodium+$potassium)-($chloride+$bicarbonate); echo round($result, 2) . "<br>"; } //Form <form name="form" method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Cations:</legend> <label for="sodium">Sodium (Na<sup>+</sup>): </label> <input type="text" name="sodium" value=" <?php if (isset($_GET['submit'])) { echo $_GET['sodium']; } ?> " tabindex="1"><br> <label for="potassium">Potassium (K<sup>+</sup>): </label> <input type="text" name="potassium" value=" <?php if (isset($_GET['submit'])) { echo $_GET['potassium']; } ?> " tabindex="2"><br> </fieldset> <fieldset> <legend>Anions:</legend> <label for="chloride">Chloride (Cl<sup>-</sup>): </label> <input type="text" name="chloride" value=" <?php if (isset($_GET['submit'])) { echo $_GET['chloride']; } ?> " tabindex="3"><br> <label for="bicarbonate">Bicarbonate (HCO<sub>3</sub><sup>-</sup>): </label> <input type="text" name="bicarbonate" value=" <?php if (isset($_GET['submit'])) { echo $_GET['bicarbonate']; } ?> " tabindex="4"><br> </fieldset> <input type="hidden" name="abbreviation" value="AnionGap"> <input type="submit" name="submit" value="Calculate" tabindex="5"> </form> //Result <?php calculate($_GET["sodium"],$_GET["potassium"],$_GET["chloride"],$_GET["bicarbonate"]); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.