DB_odbtp
[ class tree: DB_odbtp ] [ index: DB_odbtp ] [ all elements ]

Source for file northwind-access.php

Documentation is available at northwind-access.php

  1. <html>
  2. <head>
  3. <title>ODBTP PEAR DB Example: MS Access</title>
  4. </head>
  5. <body>
  6. <?php
  7.  
  8.     /*
  9.     ** This example shows how to connect to a MS Access database
  10.     ** using the PEAR DB driver for ODBTP.
  11.     */
  12.  
  13.     require"DB.php" );
  14.  
  15.     $dsn 'odbtp(access)://127.0.0.1/c:\NorthWind.mdb?rowcache=yes';
  16.  
  17.     $options['persistent'= false;
  18.     $dbh = DB::connect$dsn$options );
  19.     ifPEAR::isError$dbh ) ) {
  20.         echo "Error message: " $dbh->getMessage("<br>\n";
  21.         echo "Detailed error description: " $dbh->getDebugInfo("<br>\n";
  22.         die;
  23.     }
  24.     $sql "SELECT * FROM Customers AS C, Orders AS O "
  25.          . "WHERE O.CustomerId = C.CustomerId";
  26.     $res $dbh->query$sql );
  27.     ifPEAR::isError$res ) ) {
  28.         echo "Error message: " $res->getMessage("<br>\n";
  29.         echo "Detailed error description: " $res->getDebugInfo("<br>\n";
  30.         die;
  31.     }
  32.     do {
  33.         if!($cols $res->numCols()) ) continue;
  34.  
  35.         echo $res->numRows(" rows<p>\n";
  36.  
  37.         $colinfo $res->tableInfo();
  38.         ifPEAR::isError$colinfo ) ) {
  39.             echo "Error message: " $colinfo->getMessage("<br>\n";
  40.             echo "Detailed error description: " $colinfo->getDebugInfo("<br>\n";
  41.             die;
  42.         }
  43.         echo "<table cellpadding=2 cellspacing=0 border=1>\n";
  44.         echo "<tr>";
  45.         echo "<td>&nbsp;<b>Table</b>&nbsp;</td>";
  46.         echo "<td>&nbsp;<b>Name</b>&nbsp;</td>";
  47.         echo "<td>&nbsp;<b>Type</b>&nbsp;</td>";
  48.         echo "<td>&nbsp;<b>Length</b>&nbsp;</td>";
  49.         echo "<td>&nbsp;<b>Flags</b>&nbsp;</td>";
  50.         echo "</tr>\n";
  51.  
  52.  
  53.         for$i = 0; $i $cols$i++ {
  54.             echo "<tr>";
  55.             echo "<td>&nbsp;"$colinfo[$i]['table'"&nbsp;</td>";
  56.             echo "<td>&nbsp;"$colinfo[$i]['name'"&nbsp;</td>";
  57.             echo "<td>&nbsp;"$colinfo[$i]['type'"&nbsp;</td>";
  58.             echo "<td>&nbsp;"$colinfo[$i]['len'"&nbsp;</td>";
  59.             echo "<td>&nbsp;"$colinfo[$i]['flags'"&nbsp;</td>";
  60.             echo "</tr>\n";
  61.         }
  62.         echo "</table><p>\n";
  63.         echo "<table cellpadding=2 cellspacing=0 border=1>\n";
  64.         echo "<tr>";
  65.  
  66.         for$col = 0; $col $cols$col++ {
  67.             echo "<td><nobr>&nbsp;" $colinfo[$col]['name'"&nbsp;</nobr></td>";
  68.         }
  69.         echo "</tr>\n";
  70.  
  71.         while$row $res->fetchRow() ) {
  72.             echo "<tr>";
  73.             for$col = 0; $col $cols$col++ {
  74.                 ifis_null$row[$col) ) $row[$col"NULL";
  75.                 echo "<td valign=\"top\"><pre>";
  76.                 print_r$row[$col);
  77.                 echo "</pre></td>";
  78.             }
  79.             echo "</tr>\n";
  80.         }
  81.         echo "</table><p>\n\n";
  82.     }
  83.     while$res->nextResult() );
  84.  
  85.     $dbh->disconnect();
  86. ?>
  87. </body>
  88. </html>

Documentation generated on Mon, 11 Mar 2019 15:32:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.