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

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