home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / 08affectedrows.phpt < prev    next >
Encoding:
Text File  |  2004-03-24  |  1.5 KB  |  61 lines

  1. --TEST--
  2. DB_driver::affectedRows
  3. --SKIPIF--
  4. <?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
  5. --FILE--
  6. <?php
  7. require_once './mktable.inc';
  8.  
  9. /**
  10.  * Local error callback handler.
  11.  *
  12.  * Drops the phptest table, prints out an error message and kills the
  13.  * process.
  14.  *
  15.  * @param object  $o  PEAR error object automatically passed to this method
  16.  * @return void
  17.  * @see PEAR::setErrorHandling()
  18.  */
  19. function pe($o) {
  20.     global $dbh;
  21.  
  22.     $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  23.     $dbh->query('DROP TABLE phptest');
  24.  
  25.     die($o->toString());
  26. }
  27.  
  28. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
  29.  
  30.  
  31. // Clean table
  32. $dbh->query("DELETE FROM phptest");
  33.  
  34. // Affected rows by INSERT statement
  35. $dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')");
  36. $dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')");
  37. printf("%d after insert\n", $dbh->affectedRows());
  38.  
  39. // Affected rows by SELECT statement
  40. $dbh->query("SELECT * FROM phptest");
  41. printf("%d after select\n", $dbh->affectedRows());
  42. $dbh->query("DELETE FROM phptest WHERE b = 'test'");
  43. printf("%d after delete\n", $dbh->affectedRows());
  44.  
  45. // Affected rows by DELETE statement
  46. $dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')");
  47. $dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')");
  48. $dbh->query("DELETE FROM phptest");
  49. printf("%d after delete all\n", $dbh->affectedRows());
  50.  
  51.  
  52. $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  53. $dbh->query('DROP TABLE phptest');
  54.  
  55. ?>
  56. --EXPECT--
  57. 1 after insert
  58. 0 after select
  59. 2 after delete
  60. 2 after delete all
  61.