Page 248 - Open Soource Technologies 304.indd
P. 248

Web Technologies-I



                   Notes          $Result = $DB->query($Query);
                                  $NumResults = $Result->numRows();
                                  echo “<b>$NumResults Employees</b>”;

                                 ?>
                                  <table border=”1”>
                                  <tr>
                                   <th>First Name</th>

                                   <th>Last Name</th>
                                   <th>Title</th>
                                   <th>Email</th>
                                   <th>Extension</th>

                                  </tr>
                                 <?php
                                  while ($Row = $Result->fetchRow(DB_FETCHMODE_ASSOC))
                                  {
                                   echo ‘<tr>’;
                                   echo ‘<td>’ . $Row[‘FirstName’] . ‘</td>’;

                                   echo ‘<td>’ . $Row[‘LastName’] . ‘</td>’;
                                   echo ‘<td>’ . $Row[‘Title’] . ‘</td>’;
                                   echo ‘<td>’ . $Row[‘Email’] . ‘</td>’;
                                   echo ‘<td align=”right”>x’ . $Row[‘Extension’] . ‘</td>’;
                                   echo ‘</tr>’;
                                  }
                                 ?>

                                  </table>
                                 <?php
                                  $Result->free();
                                  $DB->disconnect();
                                 }
                                 ?>

                                 </body>
                                 </html>
                                 10.3.6 Code Explanation

                                 As you can see, the PEAR DB API is very similar to the mysqli object-oriented API. Let’s walk
                                 through the code.

                                 First, we include the PEAR DB library. Notice that we simply use DB.php for the path:
                                 require_once ‘DB.php’;



        242                               LOVELY PROFESSIONAL UNIVERSITY
   243   244   245   246   247   248   249   250   251   252   253