Industrial Strength Publishing

Components should not have to re-calculate the same result
If your components are calculating the same thing over and over again for the requests that come in, there's probably something wrong with the architecture!
<HTML>
  <HEAD><TITLE>PHP &amp; Databases</TITLE></HEAD>
  <BODY>
  <? require("$DOCUMENT_ROOT/navbars/header.html") ?>
  <?
  mysql_pconnect("localhost:3306","myuser","mypass");
  $rs=mysql_db_query("mydb","
        SELECT c.category_path, c.category_name 
        FROM story s, category c 
        WHERE s.story_id=$STORY_ID 
        AND c.category_id=s.category_id
      ");
  $row=mysql_fetch_row($rs);
  ?>
  <!-- link to the top page for this category -->
  <A HREF="<? echo $row[0] ?>"><? echo $row[1] ?></A><BR>
  <? require("$DOCUMENT_ROOT/navbars/footer.html") ?>

  </BODY>
</HTML>
In this case, PHP code connecting to the database (circa PHP3 API) for every request to calculated the link URL and link text for a link to the top level page for the category the current story is in. This is an example of what not to do!
Slide 16 of 41 Contents
 
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30
31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40
41
Print

© 2000 Ian Kallen