ChangeLog
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / checkconnectionwizard.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004 Robert Lemke (robert@typo3.org)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Check connection wizard for ADO DB databases. For usage in a popup window.
27 *
28 * @author Robert Lemke <robert@typo3.org>
29 */
30
31 /**
32 * [CLASS/FUNCTION INDEX of SCRIPT]
33 *
34 *
35 *
36 * 63: class tx_adodb_checkconnectionwizard
37 * 65: function main()
38 *
39 * TOTAL FUNCTIONS: 1
40 * (This index is automatically created/updated by the extension "extdeveval")
41 *
42 */
43
44 // Build TYPO3 enviroment:
45 $BACK_PATH='../../../typo3/';
46 define('TYPO3_MOD_PATH', 'sysext/adodb/');
47 require ($BACK_PATH.'init.php');
48 require ($BACK_PATH.'template.php');
49
50 // Include ADODB library:
51 require_once(t3lib_extMgm::extPath('adodb').'adodb/adodb.inc.php');
52
53 // Include language labels:
54 $LANG->includeLLFile('EXT:adodb/locallang_wizard.xml');
55
56 /**
57 * Script Class checking the connection to an ADODB handled database
58 *
59 * @author Robert Lemke <robert@typo3.org>
60 * @package TYPO3
61 * @subpackage adodb
62 */
63 class tx_adodb_checkconnectionwizard {
64
65 function main() {
66
67 $content = '<html><body>';
68 $conf = t3lib_div::_GP('P');
69
70 $conf['md5ID'];
71
72 if ($conf['table'] == 'tx_datasources_datasource') {
73 $dsRecord = t3lib_beFunc::getRecord($conf['table'], intval($conf['uid']));
74
75 if (is_array ($dsRecord)) {
76 $dsArr = t3lib_div::xml2array ($dsRecord['configuration']);
77 $dsConf = $dsArr['data']['sDEF']['lDEF'];
78
79 $content .= '<p>Trying to connect with Host / DSN <strong>'.htmlspecialchars($dsConf['field_host']['vDEF']).'</strong> with user <strong>'.htmlspecialchars($dsConf['field_username']['vDEF']).'</strong> ... ';
80 $dbConn = &ADONewConnection($dsConf['field_dbtype']['vDEF']);
81 $dbConn->PConnect($dsConf['field_host']['vDEF'], $dsConf['field_username']['vDEF'], $dsConf['field_password']['vDEF'], $dsConf['field_dbname']['vDEF']);
82 $dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
83
84 $content .= $dbConn->ErrorMsg();
85 if ($dbConn->_connectionID) {
86 $content .= '</p>';
87
88 $query = 'SELECT * FROM '.$dsConf['field_table']['vDEF'];
89 $recordSet = &$dbConn->SelectLimit ($query, 150);
90 if (!$recordSet) {
91 $content .= '<p>Query failed ('.htmlspecialchars($query).'):<br />';
92 $content .= $dbConn->ErrorMsg().'</p>';
93 } else {
94 $content .= '<span style="color:green">successful!</span></p>';
95 $counter = 0;
96 $content .= '<p>Showing the first 150 entries from the result recordset:</p>';
97 $content .= '<table border="1">';
98 while (!$recordSet->EOF) {
99 $content .= '<tr>';
100 if ($counter == 0) {
101 foreach (array_keys($recordSet->fields) as $key) {
102 $content .= '<th>'.htmlspecialchars($key).'</th>';
103 }
104 $content .= '</tr><tr>';
105 }
106 foreach (array_values($recordSet->fields) as $value) {
107 $content .= '<td>'.htmlspecialchars($value).'&nbsp;</td>';
108 }
109 $recordSet->MoveNext();
110 $counter++;
111 $content .= '</tr>';
112 }
113 $content .= '<table>';
114 }
115 }
116 } else {
117 $content .= '<span style="color:red">failed!</span></p><p><strong>Error Message:</strong>'. $dbConn->ErrorMsg().'</p>';
118 }
119 }
120
121 $content .= '</body></html>';
122 echo ($content);
123 }
124
125 }
126
127 // Make instance:
128 $SOBE = t3lib_div::makeInstance('tx_adodb_checkconnectionwizard');
129
130 $SOBE->main();
131
132 ?>