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

Source for file northwind-mssql.php

Documentation is available at northwind-mssql.php

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

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