[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Pear/tests/ -> transactions.inc (source)

   1  <?php
   2  
   3  // View the table from a separate connection so we don't disturb
   4  // the transaction.
   5  $dbh2 = DB::connect($dbh->dsn);
   6  
   7  function dumptable($expected) {
   8      global $dbh, $dbh2;
   9      print implode(' ', $dbh->getCol('SELECT b FROM phptest'));
  10  
  11      if (isset($dbh->transaction_opcount)) {
  12          if ($expected == $dbh->transaction_opcount) {
  13              print ".  ops=ok\n";
  14          } else {
  15              print ".  ops=$dbh->transaction_opcount\n";
  16          }
  17      } else {
  18          print ".  ops=ok\n";
  19      }
  20  }
  21  $dbh->setErrorHandling(PEAR_ERROR_DIE);
  22  $dbh->autoCommit(true);
  23  $dbh->query("INSERT INTO phptest VALUES(1, 'one', 'One', '2001-02-19')");
  24  print "after autocommit: ";
  25  dumptable(0);
  26  $dbh->autoCommit(false);
  27  $dbh->query("INSERT INTO phptest VALUES(2, 'two', 'Two', '2001-02-20')");
  28  $dbh->query("INSERT INTO phptest VALUES(3, 'three', 'Three', '2001-02-21')");
  29  print "before commit: ";
  30  dumptable(2);
  31  $dbh->commit();
  32  print "after commit: ";
  33  dumptable(0);
  34  $dbh->query("INSERT INTO phptest VALUES(4, 'four', 'Four', '2001-02-22')");
  35  $dbh->query("INSERT INTO phptest VALUES(5, 'five', 'Five', '2001-02-23')");
  36  print "before rollback: ";
  37  dumptable(2);
  38  $dbh->rollback();
  39  print "after rollback: ";
  40  dumptable(0);
  41  $dbh->autoCommit(true);
  42  $dbh->query("INSERT INTO phptest VALUES(6, 'six', 'Six', '2001-02-24')");
  43  $dbh->query("INSERT INTO phptest VALUES(7, 'seven', 'Seven', '2001-02-25')");
  44  print "before autocommit+rollback: ";
  45  dumptable(0);
  46  $dbh->rollback();
  47  print "after autocommit+rollback: ";
  48  dumptable(0);
  49  
  50  print "testing that select doesn't disturbe opcount: ";
  51  $dbh->autoCommit(false);
  52  $dbh->simpleQuery("SELECT * FROM phptest");
  53  $dbh->simpleQuery("SELECT a,c FROM phptest");
  54  $dbh->simpleQuery("SELECT b,d FROM phptest");
  55  if (empty($dbh->transaction_opcount)) {
  56      print "ok\n";
  57  } else {
  58      print "failed (count=$dbh->transaction_opcount)\n";
  59  }
  60  
  61  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7