Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/**
4
 * Tests the drivers' numRows() method
5
 *
6
 * Executed by driver/09numrows.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-2007 The PHP Group
20
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
21
 * @version    $Id: numrows.inc 239211 2007-07-06 05:19:21Z aharvey $
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, $res;
37
 
38
    $dbh->setErrorHandling(PEAR_ERROR_RETURN);
39
    $res->free();
40
    drop_table($dbh, 'phptest');
41
 
42
    print "\n------------\n";
43
    if ($o->getCode() == DB_ERROR_UNSUPPORTED) {
44
        print "This DBMS does not support numRows().";
45
    } elseif ($o->getCode() == DB_ERROR_MISMATCH) {
46
        print "Mismatch between the number of placeholders and parameters.\n";
47
        foreach ($o->backtrace as $item => $detail) {
48
            if ($detail['function'] == 'query') {
49
                echo 'QUERY: ' . $detail['args'][0] . "\n";
50
                echo "PARAMETERS:\n";
51
                print_r($detail['args'][1]);
52
            }
53
        }
54
    } else {
55
        print $o->getDebugInfo() . "\n";
56
    }
57
    exit;
58
}
59
 
60
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
61
 
62
 
63
$res = $dbh->query("SELECT a FROM phptest");
64
if (!DB::isError($rows = $res->numRows())) {
65
    print "(want 1) got $rows from first\n";
66
} else {
67
    print "\n";
68
}
69
for ($i = 0; $i < 5; $i++) {
70
    $dbh->query("INSERT INTO phptest (a) VALUES ($i)");
71
    $res = $dbh->query("SELECT a FROM phptest");
72
    if (!DB::isError($rows = $res->numRows())) {
73
        print '(want ' . ($i + 2) . ") got $rows from $i\n";
74
    } else {
75
        print "\n";
76
    }
77
}
78
 
79
$res = $dbh->query('SELECT a FROM phptest WHERE a > ?', array(0));
80
if (!DB::isError($rows = $res->numRows())) {
81
    print "(want 5) got $rows from > 0 (passing params to query)\n";
82
} else {
83
    print "\n";
84
}
85
 
86
$sth = $dbh->prepare('SELECT a FROM phptest WHERE a < ?');
87
$res = $dbh->execute($sth, array(4));
88
if (!DB::isError($rows = $res->numRows())) {
89
    print "(want 4) got $rows from < 4 (doing prepare/execute)\n";
90
} else {
91
    print "\n";
92
}
93
 
94
$dbh->query("DELETE FROM phptest WHERE a < 4");
95
$res = $dbh->query("SELECT a FROM phptest");
96
if (!DB::isError($rows = $res->numRows())) {
97
    print "(want 2) got $rows from 5 and 6 not deleted\n";
98
} else {
99
    print "\n";
100
}
101
$res = $dbh->query("SELECT a FROM phptest where a < 0");
102
if (!DB::isError($rows = $res->numRows())) {
103
    print "(want 0) got $rows from < 0\n";
104
} else {
105
    print "\n";
106
}
107
 
108
 
109
drop_table($dbh, 'phptest');