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,v 1.13 2005/02/16 13:54:52 danielc Exp $
15
 * @category Database
16
 * @author   Daniel Convissor <danielc@analysisandsolutions.com>
17
 * @internal
18
 */
19
 
20
chdir(dirname(__FILE__));
21
require_once './skipif.inc';
22
 
23
?>
24
--FILE--
25
<?php
26
 
27
// $Id: 17query.phpt,v 1.13 2005/02/16 13:54:52 danielc Exp $
28
 
29
/**
30
 * Connect to the database and make the phptest table.
31
 */
32
require_once './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, c) VALUES (17, 'one', 'One')");
64
print '2) insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
65
 
66
$res =& $dbh->query('INSERT INTO phptest (a, b, c) 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 c = ?', 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
 
126
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
127
drop_table($dbh, 'phptest');
128
 
129
?>
130
--EXPECT--
131
1) delete: okay
132
2) insert: okay
133
3) insert: okay
134
4) a = 17, b = one
135
5) a = 17, b = two
136
6) insert: okay
137
7) a = 11, b = three, d = got expected value
138
8) delete: okay
139
9) delete with array(0) as param: okay
140
10) delete with 0 as param: okay