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