[ Index ]
 

Code source de SPIP Agora 1.4

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

title

Body

[fermer]

/Pear/tests/driver/ -> 17query.phpt (source)

   1  --TEST--
   2  DB_driver::query
   3  --INI--
   4  error_reporting = 2047
   5  --SKIPIF--
   6  <?php
   7  
   8  /**
   9   * Calls the query() method in various ways against any DBMS.
  10   *
  11   * @see      DB_common::query()
  12   * 
  13   * @package  DB
  14   * @version  $Id: 17query.phpt,v 1.9 2004/09/22 22:16:47 danielc Exp $
  15   * @category Database
  16   * @author   Daniel Convissor <danielc@analysisandsolutions.com>
  17   * @internal
  18   */
  19  
  20  chdir(dirname(__FILE__));
  21  require_once  './skipif.inc';
  22  
  23  ?>
  24  --FILE--
  25  <?php
  26  
  27  // $Id: 17query.phpt,v 1.9 2004/09/22 22:16:47 danielc Exp $
  28  
  29  /**
  30   * Connect to the database and make the phptest table.
  31   */
  32  require_once  './mktable.inc';
  33  
  34  
  35  /**
  36   * Local error callback handler.
  37   *
  38   * Drops the phptest table, prints out an error message and kills the
  39   * process.
  40   *
  41   * @param object  $o  PEAR error object automatically passed to this method
  42   * @return void
  43   * @see PEAR::setErrorHandling()
  44   */
  45  function pe($o) {
  46      global $dbh;
  47  
  48      $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  49      $dbh->query('DROP TABLE phptest');
  50  
  51      die($o->toString());
  52  }
  53  
  54  $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
  55  
  56  
  57  $dbh->setFetchMode(DB_FETCHMODE_ASSOC);
  58  
  59  
  60  $res =& $dbh->query('DELETE FROM phptest WHERE a = 17');
  61  print 'delete: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
  62  
  63  $res =& $dbh->query("INSERT INTO phptest (a, b, c) VALUES (17, 'one', 'One')");
  64  print 'insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
  65  
  66  $res =& $dbh->query('INSERT INTO phptest (a, b, c) VALUES (?, ?, ?)', array(17, 'two', 'Two'));
  67  print 'insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
  68  
  69  
  70  $res =& $dbh->query('SELECT a, b FROM phptest WHERE a = 17');
  71  $row = $res->fetchRow();
  72  print "a = {$row['a']}, b = {$row['b']}\n";
  73  
  74  $res =& $dbh->query('SELECT a, b FROM phptest WHERE c = ?', array('Two'));
  75  $row = $res->fetchRow();
  76  print "a = {$row['a']}, b = {$row['b']}\n";
  77  
  78  
  79  $array = array(
  80      'foo' => 11,
  81      'bar' => 'three',
  82      'baz' => null,
  83  );
  84  $res =& $dbh->query('INSERT INTO phptest (a, b, d) VALUES (?, ?, ?)', $array);
  85  print 'insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
  86  
  87  $res =& $dbh->query('SELECT a, b, d FROM phptest WHERE a = ?', 11);
  88  $row = $res->fetchRow();
  89  print "a = {$row['a']}, b = {$row['b']}, d = ";
  90  $type = gettype($row['d']);
  91  if ($type == 'NULL' || $row['d'] == '') {
  92      print "NULL\n";
  93  } else {
  94      print "ERR: expected d's type to be NULL but it's $type and the value is ";
  95      print $row['d'] . "\n";
  96  }
  97  
  98  
  99  $res =& $dbh->query('DELETE FROM phptest WHERE a = ?', array(17));
 100  print 'delete: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
 101  
 102  
 103  $dbh->setErrorHandling(PEAR_ERROR_RETURN);
 104  $dbh->query('DROP TABLE phptest');
 105  
 106  ?>
 107  --EXPECT--
 108  delete: okay
 109  insert: okay
 110  insert: okay
 111  a = 17, b = one
 112  a = 17, b = two
 113  insert: okay
 114  a = 11, b = three, d = NULL
 115  delete: okay


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