home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / 08affectedrows.phpt < prev    next >
Encoding:
Text File  |  2004-10-01  |  1.5 KB  |  63 lines

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