DJTim666 Posted June 9, 2011 Share Posted June 9, 2011 So lets say we have a large inventory of items(5000+) held in a database. Now lets say 2000 of these items do something different than the last. Which of the following ways is more efficient? Or maybe you have your own suggestion . Store individual code bits in the DB, then pull and run <?php $item_id = $_GET['item_id']; $findItem = $db->query("select `code` from `items` where `item_id` = '{$item_id}'"); if ($findItem) { $itemCode = $db->fetch($findItem); eval ($itemCode['code']); } ?> Store all item codes in an inventory script <?php $item_id = $_GET['item_id']; switch ($item_id){ case 123: //do this break; case 124: //do this break; //continuing on for my 2000 item list } ?> I know the first one looks more efficient, but I've heard its not good to use eval :S Quote Link to comment https://forums.phpfreaks.com/topic/238893-general-scripting-question/ Share on other sites More sharing options...
The Little Guy Posted June 9, 2011 Share Posted June 9, 2011 I think that the second way would be more manageable, but then again I don't know what you are trying to accomplish. <?php $item_id = $_GET['item_id']; switch ($item_id){ case 123: require_once '../processes/item_123.php'; break; case 124: require_once '../processes/item_124.php'; break; } ?> I wouldn't recommend storing executable php code in a database. Quote Link to comment https://forums.phpfreaks.com/topic/238893-general-scripting-question/#findComment-1227506 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.