root/events/phpframework/ethna/trunk/lib/.pear/test/DB/tests/driver/01connect.phpt @ 13391

Revision 13391, 2.0 kB (checked in by maru_cc, 5 years ago)

コミット漏れがあった

Line 
1--TEST--
2DB_driver::connect
3--INI--
4error_reporting = 2047
5--SKIPIF--
6<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
7--FILE--
8<?php
9require_once './connect.inc';
10
11/**
12 * Determine if the database connection matches what's expected
13 *
14 * @param object $dbh   the PEAR DB object
15 * @param string $name  the name of the current test
16 *
17 * @return void
18 */
19function check_dbh($dbh, $name) {
20    if (DB::isError($dbh)) {
21        die('connect.inc: ' . $dbh->toString());
22    }
23    if (is_object($dbh)) {
24        print "$name is an object\n";
25    }
26    switch ($dbh->phptype) {
27        case 'dbase':
28            if (is_int($dbh->connection)) {
29                print "$name is connected\n";
30            } else {
31                print "$name NOT connected\n";
32            }
33            break;
34        case 'mysqli':
35            if (is_a($dbh->connection, 'mysqli')) {
36                print "$name is connected\n";
37            } else {
38                print "$name NOT connected\n";
39            }
40            break;
41        case 'sybase':
42            if (gettype($dbh->connection) == 'resource' ||
43                (gettype($dbh->connection) == 'integer' && $dbh->connection > 0)) {
44                print "$name is connected\n";
45            } else {
46                print "$name NOT connected\n";
47            }
48            break;
49        default:
50            if (gettype($dbh->connection) == 'resource') {
51                print "$name is connected\n";
52            } else {
53                print "$name NOT connected\n";
54            }
55    }
56}
57
58
59check_dbh($dbh, '$dbh');
60
61
62$test_array_dsn = DB::parseDSN($dsn);
63foreach ($test_array_dsn as $key => $value) {
64    if ($value === false) {
65        unset($test_array_dsn[$key]);
66    }
67}
68
69$dbha =& DB::connect($test_array_dsn, $options);
70check_dbh($dbha, '$dbha');
71
72
73$tmp  = serialize($dbha);
74$dbhu = unserialize($tmp);
75check_dbh($dbhu, '$dbhu');
76
77?>
78--EXPECT--
79$dbh is an object
80$dbh is connected
81$dbha is an object
82$dbha is connected
83$dbhu is an object
84$dbhu is connected
Note: See TracBrowser for help on using the browser.