Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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 284375 2009-07-19 16:26:16Z danielc $
15
 * @category Database
16
 * @author   Daniel Convissor <danielc@analysisandsolutions.com>
17
 * @internal
18
 */
19
 
20
chdir(dirname(__FILE__));
21
require_once dirname(__FILE__) . '/skipif.inc';
22
 
23
?>
24
--FILE--
25
<?php
26
 
27
// $Id: 17query.phpt 284375 2009-07-19 16:26:16Z danielc $
28
 
29
/**
30
 * Connect to the database and make the phptest table.
31
 */
32
require_once dirname(__FILE__) . '/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
    drop_table($dbh, '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 '1) delete: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
62
 
63
$res =& $dbh->query("INSERT INTO phptest (a, b, cc) VALUES (17, 'one', 'One')");
64
print '2) insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
65
 
66
$res =& $dbh->query('INSERT INTO phptest (a, b, cc) VALUES (?, ?, ?)', array(17, 'two', 'Two'));
67
print '3) 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 "4) a = {$row['a']}, b = {$row['b']}\n";
73
$res->free();  // keep fbsql happy.
74
 
75
$res =& $dbh->query('SELECT a, b FROM phptest WHERE cc = ?', array('Two'));
76
$row = $res->fetchRow();
77
print "5) a = {$row['a']}, b = {$row['b']}\n";
78
 
79
 
80
$array = array(
81
    'foo' => 11,
82
    'bar' => 'three',
83
    'baz' => null,
84
);
85
$res =& $dbh->query('INSERT INTO phptest (a, b, d) VALUES (?, ?, ?)', $array);
86
print '6) insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
87
 
88
$res =& $dbh->query('SELECT a, b, d FROM phptest WHERE a = ?', 11);
89
$row = $res->fetchRow();
90
print "7) a = {$row['a']}, b = {$row['b']}, d = ";
91
if ($dbh->phptype == 'msql') {
92
    if (array_key_exists('d', $row)) {
93
        $type = gettype($row['d']);
94
        if ($type == 'NULL' || $row['d'] == '') {
95
            print "got expected value\n";
96
        } else {
97
            print "ERR: expected d's type to be NULL but it's $type and the value is ";
98
            print $row['d'] . "\n";
99
        }
100
    } else {
101
        // http://bugs.php.net/?id=31960
102
        print "Prior to PHP 4.3.11 or 5.0.4, PHP's msql extension silently"
103
              . " dropped columns with null values. You need to upgrade.\n";
104
    }
105
} else {
106
    $type = gettype($row['d']);
107
    if ($type == 'NULL' || $row['d'] == '') {
108
        print "got expected value\n";
109
    } else {
110
        print "ERR: expected d's type to be NULL but it's $type and the value is ";
111
        print $row['d'] . "\n";
112
    }
113
}
114
 
115
 
116
$res =& $dbh->query('DELETE FROM phptest WHERE a = ?', array(17));
117
print '8) delete: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
118
 
119
$res =& $dbh->query('DELETE FROM phptest WHERE a = ?', array(0));
120
print '9) delete with array(0) as param: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
121
 
122
$res =& $dbh->query('DELETE FROM phptest WHERE a = ?', 0);
123
print '10) delete with 0 as param: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
124
 
125
$dbh->nextQueryIsManip(true);
126
$res =& $dbh->query('SELECT * FROM phptest');
127
print '11) query is manip (with override): ' . ($dbh->_last_query_manip ? 'true' : 'false') . "\n";
128
 
129
$dbh->nextQueryIsManip(false);
130
$res =& $dbh->query('SELECT * FROM phptest');
131
print '12) query is manip (without override): ' . ($dbh->_last_query_manip ? 'true' : 'false') . "\n";
132
 
133
// This one's here for bug #11716.
134
if ($dbh->phptype == 'msql' || $dbh->phptype == 'ibase' || $dbh->phptype == 'oci8') {
135
    // Some databases don't support quoted identifiers. They are full of lose.
136
    $res =& $dbh->query('SELECT a FROM phptest');
137
} else {
138
    $res =& $dbh->query('SELECT '.$dbh->quoteIdentifier('a').' FROM phptest');
139
}
140
 
141
print '13) select with quoteIdentifier: ';
142
$row = $res->fetchRow(DB_FETCHMODE_ASSOC);
143
if (isset($row['a'])) {
144
    if ($row['a'] == 42) {
145
        print "okay\n";
146
    } else {
147
        print "field value incorrect\n";
148
    }
149
} else {
150
    print "expected field not in row\n";
151
}
152
 
153
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
154
drop_table($dbh, 'phptest');
155
 
156
?>
157
--EXPECT--
158
1) delete: okay
159
2) insert: okay
160
3) insert: okay
161
4) a = 17, b = one
162
5) a = 17, b = two
163
6) insert: okay
164
7) a = 11, b = three, d = got expected value
165
8) delete: okay
166
9) delete with array(0) as param: okay
167
10) delete with 0 as param: okay
168
11) query is manip (with override): true
169
12) query is manip (without override): false
170
13) select with quoteIdentifier: okay