| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Tests the drivers' various fetch methods
|
|
|
5 |
*
|
|
|
6 |
* Executed by driver/02fetch.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: fetchmodes.inc,v 1.11 2005/02/14 17:04:14 danielc Exp $
|
|
|
22 |
* @link http://pear.php.net/package/DB
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Local error callback handler
|
|
|
27 |
*
|
|
|
28 |
* Drops the phptest table, prints out an error message and kills the
|
|
|
29 |
* process.
|
|
|
30 |
*
|
|
|
31 |
* @param object $o PEAR error object automatically passed to this method
|
|
|
32 |
* @return void
|
|
|
33 |
* @see PEAR::setErrorHandling()
|
|
|
34 |
*/
|
|
|
35 |
function pe($o) {
|
|
|
36 |
global $dbh;
|
|
|
37 |
|
|
|
38 |
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
|
|
39 |
drop_table($dbh, 'phptest');
|
|
|
40 |
|
|
|
41 |
die($o->toString());
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
|
|
45 |
$dbh->setOption('autofree', true);
|
|
|
46 |
|
|
|
47 |
$dbh->query("INSERT INTO phptest VALUES (1, 'one', 'One', '2001-02-16')");
|
|
|
48 |
$dbh->query("INSERT INTO phptest VALUES (2, 'two', 'Two', '2001-02-15')");
|
|
|
49 |
$dbh->query("INSERT INTO phptest VALUES (3, 'three', 'Three', '2001-02-14')");
|
|
|
50 |
|
|
|
51 |
print "testing fetchrow:\n";
|
|
|
52 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
53 |
for ($i = 1; $i <= 5; $i++) {
|
|
|
54 |
print "row $i: ";
|
|
|
55 |
$row = $sth->fetchRow();
|
|
|
56 |
if (DB::isError($row)) {
|
|
|
57 |
print $row->toString() . "\n";
|
|
|
58 |
continue;
|
|
|
59 |
}
|
|
|
60 |
if (is_array($row)) {
|
|
|
61 |
print implode(', ', $row) . "\n";
|
|
|
62 |
} else {
|
|
|
63 |
var_dump($row);
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
$sth->free(); // keep fbsql happy.
|
|
|
67 |
|
|
|
68 |
$dbh->query('DELETE FROM phptest WHERE a <> 42');
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
print "testing fetchmodes: fetchrow default default, portability mode DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM\n";
|
|
|
72 |
$dbh->setOption('portability', DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);
|
|
|
73 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
74 |
$row = $sth->fetchRow();
|
|
|
75 |
print implode(" ", array_keys($row))."\n";
|
|
|
76 |
$actual = implode(' ', array_values($row));
|
|
|
77 |
switch ($dbh->phptype) {
|
|
|
78 |
case 'fbsql':
|
|
|
79 |
case 'msql':
|
|
|
80 |
case 'mysql':
|
|
|
81 |
case 'mysqli':
|
|
|
82 |
case 'sqlite':
|
|
|
83 |
$expected = '42 bing This is a test 1999-11-21';
|
|
|
84 |
break;
|
|
|
85 |
case 'ifx':
|
|
|
86 |
$expected = '42 bing This is a test 1999-11-21 ';
|
|
|
87 |
break;
|
|
|
88 |
default:
|
|
|
89 |
$expected = '42 bing This is a test 1999-11-21';
|
|
|
90 |
}
|
|
|
91 |
if ($actual == $expected) {
|
|
|
92 |
echo "output matched expected format\n";
|
|
|
93 |
} else {
|
|
|
94 |
echo "DIDN'T MATCH! Expected output: '$expected'. Actual output: '$actual'.\n";
|
|
|
95 |
}
|
|
|
96 |
$sth->free(); // keep fbsql happy.
|
|
|
97 |
|
|
|
98 |
print "testing fetchmodes: fetchinto default default\n";
|
|
|
99 |
$dbh->setOption('portability', DB_PORTABILITY_ALL);
|
|
|
100 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
101 |
$row = array();
|
|
|
102 |
$sth->fetchInto($row);
|
|
|
103 |
print implode(" ", array_keys($row))."\n";
|
|
|
104 |
print implode(' ', array_values($row))."\n";
|
|
|
105 |
$sth->free(); // keep fbsql happy.
|
|
|
106 |
|
|
|
107 |
print "testing fetchmodes: fetchrow ordered default\n";
|
|
|
108 |
$dbh->setFetchMode(DB_FETCHMODE_ORDERED);
|
|
|
109 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
110 |
$row = $sth->fetchRow();
|
|
|
111 |
print implode(" ", array_keys($row))."\n";
|
|
|
112 |
$sth->free(); // keep fbsql happy.
|
|
|
113 |
|
|
|
114 |
print "testing fetchmodes: fetchrow assoc default\n";
|
|
|
115 |
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
|
116 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
117 |
$row = $sth->fetchRow();
|
|
|
118 |
print implode(" ", array_keys($row))."\n";
|
|
|
119 |
$sth->free(); // keep fbsql happy.
|
|
|
120 |
|
|
|
121 |
print "testing fetchmodes: fetchrow ordered default with assoc specified\n";
|
|
|
122 |
$dbh->setFetchMode(DB_FETCHMODE_ORDERED);
|
|
|
123 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
124 |
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
|
|
|
125 |
print implode(" ", array_keys($row))."\n";
|
|
|
126 |
$sth->free(); // keep fbsql happy.
|
|
|
127 |
|
|
|
128 |
print "testing fetchmodes: fetchrow assoc default with ordered specified\n";
|
|
|
129 |
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
|
130 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
131 |
$row = $sth->fetchRow(DB_FETCHMODE_ORDERED);
|
|
|
132 |
print implode(" ", array_keys($row))."\n";
|
|
|
133 |
$sth->free(); // keep fbsql happy.
|
|
|
134 |
|
|
|
135 |
print "testing fetchmodes: fetchinto ordered default\n";
|
|
|
136 |
$dbh->setFetchMode(DB_FETCHMODE_ORDERED);
|
|
|
137 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
138 |
$row = array();
|
|
|
139 |
$sth->fetchInto($row);
|
|
|
140 |
print implode(" ", array_keys($row))."\n";
|
|
|
141 |
$sth->free(); // keep fbsql happy.
|
|
|
142 |
|
|
|
143 |
print "testing fetchmodes: fetchinto assoc default\n";
|
|
|
144 |
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
|
145 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
146 |
$row = array();
|
|
|
147 |
$sth->fetchInto($row);
|
|
|
148 |
print implode(" ", array_keys($row))."\n";
|
|
|
149 |
$sth->free(); // keep fbsql happy.
|
|
|
150 |
|
|
|
151 |
print "testing fetchmodes: fetchinto ordered default with assoc specified\n";
|
|
|
152 |
$dbh->setFetchMode(DB_FETCHMODE_ORDERED);
|
|
|
153 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
154 |
$row = array();
|
|
|
155 |
$sth->fetchInto($row, DB_FETCHMODE_ASSOC);
|
|
|
156 |
print implode(" ", array_keys($row))."\n";
|
|
|
157 |
$sth->free(); // keep fbsql happy.
|
|
|
158 |
|
|
|
159 |
print "testing fetchmodes: fetchinto assoc default with ordered specified\n";
|
|
|
160 |
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
|
161 |
$sth = $dbh->query("SELECT * FROM phptest");
|
|
|
162 |
$row = array();
|
|
|
163 |
$sth->fetchInto($row, DB_FETCHMODE_ORDERED);
|
|
|
164 |
print implode(" ", array_keys($row))."\n";
|
|
|
165 |
|
|
|
166 |
$sth->free(); // keep fbsql happy.
|
|
|
167 |
// keep ibase happy: can't drop tbl that has results open against it.
|
|
|
168 |
|
|
|
169 |
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
|
|
170 |
drop_table($dbh, 'phptest');
|