1<?php
2session_cache_limiter('nocache');
3header('Content-type: text/html; charset=UTF-8');
4header('Cache-Control: public, no-cache');
5
6include_once "gda-utils.php";
7include_once "gda-exception.php";
8include_once "gda-config.php";
9
10$test_connections = false; // set to true to enable each connection testing
11
12echo "<h1>Gda connections tester</h1>\n\n";
13
14if (! try_include ("MDB2.php", true)) {
15	echo "<b>ERROR:</b> The PEAR MDB2 extension is required\n";
16	echo "<p>If you want to use the implementation provided in Libgda, then add a directive as following to the <tt>gda-config.php</tt> file:</p>";
17	echo "<p><tt>set_include_path (get_include_path().\":PEAR_MDB2\");</tt></p>";
18	echo "<p>Note that you still need to install the PEAR package (named 'php-pear' on a Debian system).</p>";
19	exit (1);
20}
21
22if (! extension_loaded ("SimpleXML")) {
23	echo "<b>ERROR</b>: The SimpleXML extension is required\n";
24	echo "<p>You need to configure PHP to include this extension.</p>";
25	exit (1);
26}
27
28function handle_pear_error ($res)
29{
30	if (PEAR::isError($res)) {
31		$cause = "<p><b>Standard Message:</b> ".$res->getMessage()."</p>\n".
32			"<p><b>User Information:</b> ".$res->getUserInfo()."</p>\n".
33			"<p><b>Debug Information:</b> ".$res->getDebugInfo()."</p>";
34		throw new GdaException($cause, false);
35	}
36}
37
38echo "\n";
39
40if (! isset ($cnc, $dsn)) {
41	echo "<p><b>ERROR:</b> No connection defined!</p>\n";
42	exit (1);
43}
44
45if ($test_connections) {
46	foreach ($cnc as $dbname => $dbpass) {
47		echo "<h2>Connection '".$dbname."'</h2>";
48		try {
49			$mdb2 = MDB2::connect($dsn[$dbname]);
50			handle_pear_error ($mdb2);
51			echo "OK.\n";
52		}
53		catch (GdaException $e) {
54			echo "FAILED!\n".$e->getMessage()."\n";
55		}
56	}
57}
58else {
59	echo "<p>Connections listed below but not tested (set <tt>\$test_connections</tt> to <tt>true</tt> in the <tt>gda-config.php</tt> file to change):</p>\n";
60	echo "<ul>\n";
61	foreach ($cnc as $dbname => $dbpass) {
62		echo "<li>Connection '".$dbname."'</li>\n";
63	}
64	echo "</ul>\n";
65}
66?>
67