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

Source for file ado_test.php

Documentation is available at ado_test.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2003 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 2.02 of the PHP license,      |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://www.php.net/license/2_02.txt.                                 |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Author: Alexios Fakos (alex@fakos.de)                                |
  16. // +----------------------------------------------------------------------+
  17.  
  18.  
  19. // This is my test script, feel free to use it.
  20.  
  21.  
  22. // due tableinfo() ADODB.Field properties depends on provider. some values are not supported
  23. // therefore you get warnings PropGet() failed... 
  24. error_reporting(E_PARSE | E_ERROR | E_CORE_ERROR | E_USER_ERROR);
  25.  
  26. require_once ('DB.php');
  27.  
  28. $dsn = array(
  29.     'phptype'  => "ado",
  30.     'dbsyntax' => "access"// or mssql or odbc
  31.     'username' => "",
  32.     'username' => "Admin",  // or sa
  33.     'password' => "",
  34.     'database' => "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Programs\\Microsoft Office\\Office\\Samples\\Nordwind.mdb;Persist Security Info=False"
  35. //    'database' => "Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Northwind;"
  36. );
  37.  
  38.     $conn = DB::connect($dsnTRUE);
  39.  
  40.     assertObject($conn);
  41.  
  42.  
  43. //  select your fetchmode to test (DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT)19.04.2002
  44.     $conn->setFetchMode(DB_FETCHMODE_ASSOC);
  45.  
  46.  
  47. printH2("Fetch row functions");
  48.  
  49.     $sql "SELECT TOP 10 * FROM Customers";
  50.  
  51.     $rs $conn->query($sql);
  52.     $i = 1;
  53.     
  54.     assertObject($rs);
  55.     while ($row $rs->fetchRow()) {
  56.         printLoop($row$i);
  57.     }
  58.  
  59.     printHR();
  60.     
  61.     
  62.  
  63.     $sql "SELECT TOP 5 * FROM Employees";
  64.  
  65.     $rs $conn->query($sql);
  66.     $i = 1;
  67.  
  68.     assertObject($rs);
  69.     while ($rs->fetchInto($row)) {
  70.         printLoop($row$i);
  71.     }
  72.  
  73.     printHR();
  74.  
  75.     
  76.  
  77.     $sql "SELECT TOP 10 * FROM Orders";
  78.  
  79.     $rs $conn->query($sql);
  80.     $i = 1;
  81.  
  82.     assertObject($rs);
  83.     while ($row $rs->FetchRow()) {
  84.         printLoop($row$i);
  85.     }
  86.  
  87.     printHR();
  88.  
  89.     
  90.  
  91. // next examples taken from http://vulcanonet.com/soft/?pack=pear_tut#ss3.3.5
  92.  
  93.  
  94. printH2("Fetch rows by number");
  95.  
  96.     $i = 1;
  97.     $sql "SELECT * FROM Employees";
  98.     $from = 1;
  99.     $res_per_page = 6;
  100.     $to $from $res_per_page;
  101.     $fetchmode = DB_FETCHMODE_ASSOC; //(DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT)
  102.     $rs $conn->query($sql);
  103.     assertObject($rs);
  104.     
  105.     foreach (range($from$toas $rownum{
  106.         if (!$row $rs->fetchRow($fetchmode$rownum)) {
  107.             break;
  108.         }
  109.         printLoop($row$i);
  110.     }    
  111.  
  112.  
  113.     printHR();
  114.  
  115.  
  116.     
  117.  
  118. printH2("Quick data retrieving");
  119.     
  120.     $sql "SELECT TOP 5 * FROM Suppliers";
  121.  
  122.     echo "<b>getOne</b>\n";
  123.     $rs $conn->getOne($sql);
  124.     assertObject($rs);
  125.     echo var_dump($rs);
  126.  
  127.  
  128.     
  129.  
  130.     printHR();
  131.  
  132.     echo "<b>getRow</b>\n";
  133.     $row $conn->getRow($sql);
  134.     assertObject($row);
  135.     echo var_dump($row);
  136.  
  137.  
  138.     
  139.     printHR();
  140.  
  141.  
  142.     $sql "SELECT TOP 10 CompanyName FROM Suppliers";
  143.  
  144.     echo "<b>getCol</b>\n";
  145.     $row $conn->getCol($sql);
  146.     assertObject($row);
  147.     echo var_dump($row);
  148.  
  149.  
  150.     
  151.     printHR();
  152.  
  153.     $sql "SELECT TOP 5 * FROM Suppliers";
  154.  
  155.     echo "<b>getAssoc</b>\n";
  156.     $rs $conn->getAssoc($sql);
  157.     assertObject($rs);
  158.     echo var_dump($rs);
  159.  
  160.     
  161.     printHR();
  162.  
  163.  
  164.     
  165.     echo "<b>getAll</b>\n";
  166.     $rs $conn->getAll($sql);
  167.     assertObject($rs);
  168.     echo var_dump($rs);
  169.  
  170.     
  171.     printHR();
  172.  
  173.  
  174.  
  175. printH2("Infos from query result");
  176.     
  177.     $rs $conn->query($sql);
  178.     assertObject($rs);
  179.  
  180.     echo "<b>numRows</b>\n";
  181.     echo $rs->numRows();
  182.     assertObject($rs);
  183.     
  184.     printBR();
  185.     echo "<b>numCols</b>\n";
  186.     echo $rs->numCols();
  187.     assertObject($rs);
  188.  
  189.     printHR();
  190.  
  191.     echo "tableInfo";
  192.     echo $res->tableInfo();
  193.  
  194. /*
  195.     printBR();
  196.     echo "Affected rows\n";
  197.  
  198.     $sql = "DELETE FROM _test";     // use your own table:)
  199.     $rs = $conn->query($sql);
  200.     assertObject($rs);
  201.     echo 'I have deleted ' . $conn->affectedRows() . ' rows';
  202.  
  203.     printHR();
  204. */
  205.  
  206.     printHR();
  207.  
  208. printH2("Sequences");
  209.  
  210.     $rs $conn->nextId("alex_3");
  211.     assertObject($rs);
  212.     echo $rs;
  213.  
  214.     printBR();
  215.     $rs $conn->nextId("alex_3");
  216.     assertObject($rs);
  217.  
  218.     echo $rs;
  219.  
  220.  
  221.     printHR();
  222.  
  223.  
  224. printH2("Free the results");
  225.     
  226. //    $rs->free(); no need after sequence stuff
  227.     assertObject($conn);
  228.     $conn->disconnect();
  229.     assertObject($conn);
  230.  
  231.     echo "done";
  232.  
  233.  
  234.  
  235.     function printHR()
  236.     {
  237.         echo "<br/>\n<hr/>\n<br/>";
  238.     // end func
  239.  
  240.     function printBR()
  241.     {
  242.         echo "<br/>";
  243.     // end func
  244.     
  245.     function assertObject(&$obj)
  246.     {
  247.         if (DB::isError($obj)) {        
  248.             die ($obj->toString());
  249.         }        
  250.     // end func
  251.  
  252.     
  253.     
  254.  
  255.     function printLoop(&$obj&$counter)
  256.     {
  257.         assertObject($obj);
  258.         echo "<b>" $counter++ . "</b>"
  259.         printBR()
  260.         echo var_dump($obj)
  261.         printBR();
  262.         
  263.     // end func ()
  264.  
  265.  
  266.     function printH2($caption="")
  267.     {
  268.         echo "<h2>" $caption "</h2>";        
  269.     // end func ()
  270.  
  271. ?>

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