home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / numrows.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  2.1 KB  |  93 lines

  1. <?php
  2.  
  3. /**
  4.  * Local error callback handler.
  5.  *
  6.  * Drops the phptest table, prints out an error message and kills the
  7.  * process.
  8.  *
  9.  * @param object  $o  PEAR error object automatically passed to this method
  10.  * @return void
  11.  * @see PEAR::setErrorHandling()
  12.  */
  13. function pe($o) {
  14.     global $dbh;
  15.  
  16.     $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  17.     $dbh->query('DROP TABLE phptest');
  18.  
  19.     die($o->toString());
  20. }
  21.  
  22. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
  23.  
  24.  
  25. $sth = $dbh->query("SELECT a FROM phptest");
  26. switch ($dbh->phptype) {
  27.     case 'ibase':
  28.         /*
  29.          * Interbase doesn't allow manipulating tables that have result
  30.          * sets still open.
  31.          */
  32.         $dbh->freeResult($sth->result);
  33.         break;
  34. }
  35. if (!DB::isError($rows = $sth->numRows())) {
  36.     print "$rows from first\n";
  37. } else {
  38.     print "\n";
  39. }
  40. for ($i = 0; $i < 5; $i++) {
  41.     $sth = $dbh->query("INSERT INTO phptest (a) VALUES ($i)");
  42.     $sth = $dbh->query("SELECT a FROM phptest");
  43.     if (!DB::isError($rows = $sth->numRows())) {
  44.         print "$rows from $i\n";
  45.     } else {
  46.         print "\n";
  47.     }
  48. }
  49.  
  50. $sth = $dbh->query('SELECT a FROM phptest WHERE a > ?', 0);
  51. if (!DB::isError($rows = $sth->numRows())) {
  52.     print "$rows from > 0\n";
  53. } else {
  54.     print "\n";
  55. }
  56.  
  57. $sth = $dbh->prepare('SELECT a FROM phptest WHERE a < ?');
  58. $res = $dbh->execute($sth, array(4));
  59. if (!DB::isError($rows = $res->numRows())) {
  60.     print "$rows from < 4\n";
  61. } else {
  62.     print "\n";
  63. }
  64.  
  65. $dbh->query("DELETE FROM phptest WHERE a < 4");
  66. $sth = $dbh->query("SELECT a FROM phptest");
  67. if (!DB::isError($rows = $sth->numRows())) {
  68.     print "$rows from 5 and 6 not deleted\n";
  69. } else {
  70.     print "\n";
  71. }
  72. $sth = $dbh->query("SELECT a FROM phptest where a < 0");
  73. if (!DB::isError($rows = $sth->numRows())) {
  74.     print "$rows from < 0\n";
  75. } else {
  76.     print "\n";
  77. }
  78.  
  79.  
  80. switch ($dbh->phptype) {
  81.     case 'ibase':
  82.         /*
  83.          * Interbase doesn't allow dropping tables that have result
  84.          * sets still open.
  85.          */
  86.         $dbh->freeResult($sth->result);
  87.         break;
  88. }
  89. $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  90. $dbh->query('DROP TABLE phptest');
  91.  
  92. ?>
  93.