File: 01connect.phpt

package info (click to toggle)
php-db 1.7.13-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 872 kB
  • ctags: 1,600
  • sloc: php: 6,913; pascal: 1,001; xml: 198; makefile: 55; sh: 24
file content (84 lines) | stat: -rw-r--r-- 2,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--TEST--
DB_driver::connect
--INI--
error_reporting = 2047
--SKIPIF--
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
--FILE--
<?php
require_once './connect.inc';

/**
 * Determine if the database connection matches what's expected
 *
 * @param object $dbh   the PEAR DB object
 * @param string $name  the name of the current test
 *
 * @return void
 */
function check_dbh($dbh, $name) {
    if (DB::isError($dbh)) {
        die('connect.inc: ' . $dbh->toString());
    }
    if (is_object($dbh)) {
        print "$name is an object\n";
    }
    switch ($dbh->phptype) {
        case 'dbase':
            if (is_int($dbh->connection)) {
                print "$name is connected\n";
            } else {
                print "$name NOT connected\n";
            }
            break;
        case 'mysqli':
            if (is_a($dbh->connection, 'mysqli')) {
                print "$name is connected\n";
            } else {
                print "$name NOT connected\n";
            }
            break;
        case 'sybase':
            if (gettype($dbh->connection) == 'resource' ||
                (gettype($dbh->connection) == 'integer' && $dbh->connection > 0)) {
                print "$name is connected\n";
            } else {
                print "$name NOT connected\n";
            }
            break;
        default:
            if (gettype($dbh->connection) == 'resource') {
                print "$name is connected\n";
            } else {
                print "$name NOT connected\n";
            }
    }
}


check_dbh($dbh, '$dbh');


$test_array_dsn = DB::parseDSN($dsn);
foreach ($test_array_dsn as $key => $value) {
    if ($value === false) {
        unset($test_array_dsn[$key]);
    }
}

$dbha =& DB::connect($test_array_dsn, $options);
check_dbh($dbha, '$dbha');


$tmp  = serialize($dbha);
$dbhu = unserialize($tmp);
check_dbh($dbhu, '$dbhu');

?>
--EXPECT--
$dbh is an object
$dbh is connected
$dbha is an object
$dbha is connected
$dbhu is an object
$dbhu is connected