Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.