Web Analytics Made Easy -
StatCounter database vs files - CodingForum

Announcement

Collapse
No announcement yet.

database vs files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • database vs files

    Hi there i am creating a new site and i want the banner to be changing dynamically. I was thinking that i can write a script that reads the image files from the folders and picks up one randomly.
    Another way is to implement that using a conenction to a database. What u think is much faster? Is the multiple connections to the database reason for bottlenecks?

  • #2
    Well, my 2 cents:
    - images should not be stored in a db. Only the images adress shoudl be stored inthere
    - if you just need a random select, then use a randomizer function in your server side script.

    So you don't need a db to store the images, and you don't need it to get the random imageselect.

    <<<< What u think is much faster? >>>>
    The file sollution. Not the db sollution.

    <<<<Is the multiple connections to the database reason for bottlenecks?>>>>
    I don't quite understand what this has to do with it.
    MySQL is real fast for selectquerys and it ca easely deal with over 200 concurrent threads, so i don't thaink that the number of concurrent users would be a problem.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      thx

      <<<< What u think is much faster? >>>>
      The file sollution. Not the db sollution.


      Axa...Can u support your opinion? It is much more important for me to learn the reason rather than the answer

      Thx a lot

      Comment


      • #4
        it's quite evident that if you can cut out the dbconnection, the query-execution, the recordset-sending and the recordsetprocessing , that you then will gain some executiontime.
        And you wount be using up ay db-resources or bandwidth to get your data.

        I mean, suppose you have 7 images. If you just store the images like
        /inc/7.gif
        /inc/6.gif
        ...
        then all you need to do to select and display a random image
        PHP Code:
        echo('<img src="./inc/' rand(1,7) . '.gif" alt="My sites banner!" width="795" height="32" />'); 
        rand --> http://www.php.net/rand

        Or if you need more parameters per image (like the alt, url etc, then you can use array_rand
        Check out http://be.php.net/function.array-rand

        There is a usercommens (in fact, the most recent one, talking about luck, that does exactly what you would need then)

        PHP Code:
        /*jpinedo
        02-Nov-2003 07:15 
        An array of arrays example:*/

        $banners[0]['imagen']="imagen0.gif";
        $banners[0]['url']="www.nosenada.tal";

        $banners[1]['imagen']="imagen1.gif";
        $banners[1]['url']="www.nose.tal";

        $banners[2]['imagen']="imagen2.gif";
        $banners[2]['url']="pagina.html";

        $banners[3]['imagen']="imagen3.jpg";
        $banners[3]['url']="../pagina.php";

        $id_banner array_rand($banners);

        echo  
        "Archivo:--".$banners[$id_banner]['imagen']. "<br />\n";
        echo  
        "URL:-----".$banners[$id_banner]['url']. "<br />\n"
        The only reason to choose for the db-sollution would be if you will be replacing the images (new images with a new name) frequently, and if you would do this through a web-interface or another tool that both does the file-operation + that automatically updates the db.
        Then the 'loss' in performance will be acceptable because it would be compensated by the gain in maintenance-time you need to spend on an image-swap.
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment

        Working...
        X