Jump to content

General Scripting Question


DJTim666

Recommended Posts

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 :P.

 

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

Link to comment
https://forums.phpfreaks.com/topic/238893-general-scripting-question/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.