DB
[ class tree: DB ] [ index: DB ] [ all elements ]

Source for file fetchmode_object.inc

Documentation is available at fetchmode_object.inc

  1. <?php
  2.  
  3. /**
  4.  * Tests the drivers' object fetch mode procedures
  5.  *
  6.  * Executed by driver/14fetchmode_object.phpt
  7.  *
  8.  * PHP versions 4 and 5
  9.  *
  10.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  11.  * that is available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13.  * the PHP License and are unable to obtain it through the web, please
  14.  * send a note to license@php.net so we can mail you a copy immediately.
  15.  *
  16.  * @category   Database
  17.  * @package    DB
  18.  * @author     Daniel Convissor <danielc@php.net>
  19.  * @copyright  1997-2005 The PHP Group
  20.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  21.  * @version    $Id: fetchmode_object.inc,v 1.11 2005/02/03 05:49:44 danielc Exp $
  22.  * @link       http://pear.php.net/package/DB
  23.  */
  24.  
  25.  
  26. /**
  27.  * Local error callback handler
  28.  *
  29.  * Drops the phptest table, prints out an error message and kills the
  30.  * process.
  31.  *
  32.  * @param object  $o  PEAR error object automatically passed to this method
  33.  * @return void 
  34.  * @see PEAR::setErrorHandling()
  35.  */
  36. function pe($o{
  37.     global $dbh;
  38.  
  39.     $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  40.     drop_table($dbh'phptest');
  41.  
  42.     die($o->toString());
  43. }
  44.  
  45. /**
  46.  * Print out the object
  47.  */
  48. function print_obj(&$obj{
  49.     if (!is_object($obj)) {
  50.         echo "ERROR: no object!\n";
  51.     else {
  52.         echo strtolower(get_class($obj)) ' -> ' implode(' 'array_keys((array)$obj)) "\n";
  53.     }
  54. }
  55.  
  56.  
  57. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK'pe');
  58.  
  59. echo "--- fetch with param DB_FETCHMODE_OBJECT ---\n";
  60. $sth $dbh->query("SELECT * FROM phptest");
  61. $row $sth->fetchRow(DB_FETCHMODE_OBJECT);
  62. print_obj($row);
  63. $sth->free();  // keep fbsql happy.
  64.  
  65. $sth $dbh->query("SELECT * FROM phptest");
  66. $sth->fetchInto($rowDB_FETCHMODE_OBJECT);
  67. print_obj($row);
  68. $sth->free();  // keep fbsql happy.
  69.  
  70. echo "--- fetch with default fetchmode DB_FETCHMODE_OBJECT ---\n";
  71. $dbh->setFetchMode(DB_FETCHMODE_OBJECT);
  72. $sth $dbh->query("SELECT * FROM phptest");
  73. $row $sth->fetchRow();
  74. print_obj($row);
  75. $sth->free();  // keep fbsql happy.
  76.  
  77. $sth $dbh->query("SELECT * FROM phptest");
  78. $sth->fetchInto($row);
  79. print_obj($row);
  80. $sth->free();  // keep fbsql happy.
  81.  
  82. echo "--- fetch with default fetchmode DB_FETCHMODE_OBJECT and class DB_row ---\n";
  83. $dbh->setFetchMode(DB_FETCHMODE_OBJECT'DB_row');
  84. $sth $dbh->query("SELECT * FROM phptest");
  85. $row $sth->fetchRow();
  86. print_obj($row);
  87. $sth->free();  // keep fbsql happy.
  88.  
  89. $sth $dbh->query("SELECT * FROM phptest");
  90. $sth->fetchInto($row);
  91. print_obj($row);
  92. $sth->free();  // keep fbsql happy.
  93.  
  94. echo "--- fetch with default fetchmode DB_FETCHMODE_OBJECT with no class then DB_row ---\n";
  95. $dbh->setFetchMode(DB_FETCHMODE_OBJECT);
  96. $sth $dbh->query('SELECT * FROM phptest');
  97. $row $sth->fetchRow();
  98. print_obj($row);
  99. $sth->free();  // keep fbsql happy.
  100.  
  101. $dbh->setFetchMode(DB_FETCHMODE_OBJECT'DB_row');
  102. $sth $dbh->query('SELECT * FROM phptest');
  103. $row $sth->fetchRow();
  104. print_obj($row);
  105.  
  106. $sth->free();  // keep fbsql happy.
  107.                // keep ibase happy: can't drop tbl that has results open against it.
  108.  
  109. $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  110. drop_table($dbh'phptest');

Documentation generated on Tue, 20 Mar 2007 05:30:31 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.