| 1 |
lars |
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 |
error_reporting(E_ALL);
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Local error callback handler
|
|
|
29 |
*
|
|
|
30 |
* Drops the phptest table, prints out an error message and kills the
|
|
|
31 |
* process.
|
|
|
32 |
*
|
|
|
33 |
* @param object $o PEAR error object automatically passed to this method
|
|
|
34 |
* @return void
|
|
|
35 |
* @see PEAR::setErrorHandling()
|
|
|
36 |
*/
|
|
|
37 |
function pe($o) {
|
|
|
38 |
global $dbh;
|
|
|
39 |
|
|
|
40 |
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
|
|
41 |
drop_table($dbh, 'phptest');
|
|
|
42 |
|
|
|
43 |
die($o->toString());
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Print out the object
|
|
|
48 |
*/
|
|
|
49 |
function print_obj(&$obj) {
|
|
|
50 |
if (!is_object($obj)) {
|
|
|
51 |
echo "ERROR: no object!\n";
|
|
|
52 |
} else {
|
|
|
53 |
echo strtolower(get_class($obj)) . ' -> ' . implode(' ', array_keys((array)$obj)) . "\n";
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
|
|
59 |
|
|
|
60 |
echo "--- fetch with param DB_FETCHMODE_OBJECT ---\n";
|
|
|
61 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
62 |
$row = $sth->fetchRow(DB_FETCHMODE_OBJECT);
|
|
|
63 |
print_obj($row);
|
|
|
64 |
$sth->free(); // keep fbsql happy.
|
|
|
65 |
|
|
|
66 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
67 |
$sth->fetchInto($row, DB_FETCHMODE_OBJECT);
|
|
|
68 |
print_obj($row);
|
|
|
69 |
$sth->free(); // keep fbsql happy.
|
|
|
70 |
|
|
|
71 |
echo "--- fetch with default fetchmode DB_FETCHMODE_OBJECT ---\n";
|
|
|
72 |
$dbh->setFetchMode(DB_FETCHMODE_OBJECT);
|
|
|
73 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
74 |
$row = $sth->fetchRow();
|
|
|
75 |
print_obj($row);
|
|
|
76 |
$sth->free(); // keep fbsql happy.
|
|
|
77 |
|
|
|
78 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
79 |
$sth->fetchInto($row);
|
|
|
80 |
print_obj($row);
|
|
|
81 |
$sth->free(); // keep fbsql happy.
|
|
|
82 |
|
|
|
83 |
echo "--- fetch with default fetchmode DB_FETCHMODE_OBJECT and class DB_row ---\n";
|
|
|
84 |
$dbh->setFetchMode(DB_FETCHMODE_OBJECT, 'DB_row');
|
|
|
85 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
86 |
$row = $sth->fetchRow();
|
|
|
87 |
print_obj($row);
|
|
|
88 |
$sth->free(); // keep fbsql happy.
|
|
|
89 |
|
|
|
90 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
91 |
$sth->fetchInto($row);
|
|
|
92 |
print_obj($row);
|
|
|
93 |
$sth->free(); // keep fbsql happy.
|
|
|
94 |
|
|
|
95 |
echo "--- fetch with default fetchmode DB_FETCHMODE_OBJECT with no class then DB_row ---\n";
|
|
|
96 |
$dbh->setFetchMode(DB_FETCHMODE_OBJECT);
|
|
|
97 |
$sth = $dbh->query('SELECT * FROM phptest');
|
|
|
98 |
$row = $sth->fetchRow();
|
|
|
99 |
print_obj($row);
|
|
|
100 |
$sth->free(); // keep fbsql happy.
|
|
|
101 |
|
|
|
102 |
$dbh->setFetchMode(DB_FETCHMODE_OBJECT, 'DB_row');
|
|
|
103 |
$sth = $dbh->query('SELECT * FROM phptest');
|
|
|
104 |
$row = $sth->fetchRow();
|
|
|
105 |
print_obj($row);
|
|
|
106 |
|
|
|
107 |
$sth->free(); // keep fbsql happy.
|
|
|
108 |
// keep ibase happy: can't drop tbl that has results open against it.
|
|
|
109 |
|
|
|
110 |
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
|
|
111 |
drop_table($dbh, 'phptest');
|