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' limitQuery() method
5
 *
6
 * Executed by driver/13limit.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: limit.inc,v 1.11 2005/02/03 05:49:44 danielc Exp $
22
 * @link       http://pear.php.net/package/DB
23
 */
24
 
25
error_reporting(E_ALL);
26
 
27
/**
28
 * Local error callback handler
29
 *
30
 * Drops the phptest table, prints out an error message and kills the
31
 * process.
32
 *
33
 * @param object  $o  PEAR error object automatically passed to this method
34
 * @return void
35
 * @see PEAR::setErrorHandling()
36
 */
37
function pe($o) {
38
    global $dbh;
39
 
40
    $dbh->setErrorHandling(PEAR_ERROR_RETURN);
41
    drop_table($dbh, 'phptest');
42
 
43
    die($o->toString());
44
}
45
 
46
 
47
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
48
drop_table($dbh, 'php_limit');
49
 
50
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
51
 
52
$dbh->query('CREATE TABLE php_limit (a CHAR(20))');
53
 
54
 
55
$from    = 0;
56
$count   = 10;
57
$numrows = 30;
58
 
59
for ($i=0; $i<=$numrows+2; $i++) {
60
    $dbh->query("INSERT INTO php_limit VALUES('result $i')");
61
}
62
for ($i = 0; $i <= 3; $i++) {
63
    $from = 10 * $i;
64
    $res = $dbh->limitQuery("select * from php_limit", $from, $count);
65
    echo "======= From: $from || Number of rows to fetch: $count =======\n";
66
    while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
67
        echo $res->getRowCounter() . '.- ' . $row['a'] . "\n";
68
    }
69
    $res->free();  // keep fbsql happy.
70
}
71
 
72
 
73
$from  = 11;
74
$count = 3;
75
 
76
echo "======= Passing \$params || From: $from || Number of rows to fetch: $count =======\n";
77
$res = $dbh->limitQuery('SELECT * FROM php_limit WHERE a < ?', $from, $count, array('result 99'));
78
while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
79
    echo $res->getRowCounter() . '.- ' . $row['a'] . "\n";
80
}
81
 
82
$res->free();  // keep fbsql happy.
83
               // keep ibase happy: can't drop tbl that has results open against it.
84
 
85
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
86
drop_table($dbh, 'php_limit');