1<?php
2
3/**
4 * Tests the various ways DB's connect() function operates
5 *
6 * PHP version 5
7 *
8 * LICENSE: This source file is subject to version 3.0 of the PHP license
9 * that is available through the world-wide-web at the following URI:
10 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
11 * the PHP License and are unable to obtain it through the web, please
12 * send a note to license@php.net so we can mail you a copy immediately.
13 *
14 * @category   Database
15 * @package    DB
16 * @author     Daniel Convissor <danielc@php.net>
17 * @copyright  1997-2007 The PHP Group
18 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
19 * @version    $Id$
20 * @link       http://pear.php.net/package/DB
21 * @since      File available since Release 1.7.0
22 */
23
24/**
25 * Establish the include_path, DSN's and connection $options
26 */
27require_once dirname(__FILE__) . '/setup.inc';
28
29foreach ($dsns as $dbms => $dsn) {
30    echo "======== $dbms ========\n";
31    $options['persistent'] = false;
32    $dbh = DB::connect($dsn, $options);
33    if (DB::isError($dbh)) {
34        echo 'PROBLEM: ' . $dbh->getUserInfo() . "\n";
35        continue;
36    }
37
38    if ($dbh->provides('new_link')
39        && version_compare(phpversion(), $dbh->provides('new_link'), '>='))
40    {
41        $probs = false;
42        $dsn = DB::parseDSN($dsn);
43        $dsn['new_link'] = true;
44        $dbh = DB::connect($dsn, $options);
45        if (DB::isError($dbh)) {
46            echo 'NEW LINK PROBLEM: ' . $dbh->getUserInfo() . "\n";
47            $probs = true;
48        }
49
50        if ($dbh->provides('pconnect')) {
51            $options['persistent'] = true;
52            $dbh->disconnect();
53            $dbh = DB::connect($dsn, $options);
54            if (DB::isError($dbh)) {
55                echo 'PERSIST NEWCON PROBLEM: ' . $dbh->getUserInfo() . "\n";
56                $probs = true;
57            }
58
59            unset($dsn['new_link']);
60            $dbh->disconnect();
61            $dbh = DB::connect($dsn, $options);
62            if (DB::isError($dbh)) {
63                echo 'PERSIST OLDCON PROBLEM: ' . $dbh->getUserInfo() . "\n";
64                $probs = true;
65            }
66        }
67        if ($probs) {
68            continue;
69        }
70        $dbh->disconnect();
71
72    } elseif ($dbh->provides('pconnect')) {
73        $options['persistent'] = true;
74        $dbh->disconnect();
75        $dbh = DB::connect($dsn, $options);
76        if (DB::isError($dbh)) {
77            echo 'PERSIST PROBLEM: ' . $dbh->getUserInfo() . "\n";
78            continue;
79        }
80        $dbh->disconnect();
81    }
82    echo "GOOD\n";
83}
84