|
indvdum@0
|
1 |
<?php
|
|
indvdum@0
|
2 |
/**
|
|
indvdum@0
|
3 |
*
|
|
indvdum@0
|
4 |
* @package install
|
|
indvdum@0
|
5 |
* @version $Id$
|
|
indvdum@0
|
6 |
* @copyright (c) 2006 phpBB Group
|
|
indvdum@0
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
indvdum@0
|
8 |
*
|
|
indvdum@0
|
9 |
*/
|
|
indvdum@0
|
10 |
|
|
indvdum@0
|
11 |
/**
|
|
indvdum@0
|
12 |
* @ignore
|
|
indvdum@0
|
13 |
*/
|
|
indvdum@0
|
14 |
if (!defined('IN_PHPBB'))
|
|
indvdum@0
|
15 |
{
|
|
indvdum@0
|
16 |
exit;
|
|
indvdum@0
|
17 |
}
|
|
indvdum@0
|
18 |
|
|
indvdum@0
|
19 |
/**
|
|
indvdum@0
|
20 |
* Determine if we are able to load a specified PHP module and do so if possible
|
|
indvdum@0
|
21 |
*/
|
|
indvdum@0
|
22 |
function can_load_dll($dll)
|
|
indvdum@0
|
23 |
{
|
|
indvdum@0
|
24 |
// SQLite2 is a tricky thing, from 5.0.0 it requires PDO; if PDO is not loaded we must state that SQLite is unavailable
|
|
indvdum@0
|
25 |
// as the installer doesn't understand that the extension has a prerequisite.
|
|
indvdum@0
|
26 |
//
|
|
indvdum@0
|
27 |
// On top of this sometimes the SQLite extension is compiled for a different version of PDO
|
|
indvdum@0
|
28 |
// by some Linux distributions which causes phpBB to bomb out with a blank page.
|
|
indvdum@0
|
29 |
//
|
|
indvdum@0
|
30 |
// Net result we'll disable automatic inclusion of SQLite support
|
|
indvdum@0
|
31 |
//
|
|
indvdum@0
|
32 |
// See: r9618 and #56105
|
|
indvdum@0
|
33 |
if ($dll == 'sqlite')
|
|
indvdum@0
|
34 |
{
|
|
indvdum@0
|
35 |
return false;
|
|
indvdum@0
|
36 |
}
|
|
indvdum@0
|
37 |
return ((@ini_get('enable_dl') || strtolower(@ini_get('enable_dl')) == 'on') && (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') && function_exists('dl') && @dl($dll . '.' . PHP_SHLIB_SUFFIX)) ? true : false;
|
|
indvdum@0
|
38 |
}
|
|
indvdum@0
|
39 |
|
|
indvdum@0
|
40 |
/**
|
|
indvdum@0
|
41 |
* Returns an array of available DBMS with some data, if a DBMS is specified it will only
|
|
indvdum@0
|
42 |
* return data for that DBMS and will load its extension if necessary.
|
|
indvdum@0
|
43 |
*/
|
|
indvdum@0
|
44 |
function get_available_dbms($dbms = false, $return_unavailable = false, $only_20x_options = false)
|
|
indvdum@0
|
45 |
{
|
|
indvdum@0
|
46 |
global $lang;
|
|
indvdum@0
|
47 |
$available_dbms = array(
|
|
indvdum@0
|
48 |
'firebird' => array(
|
|
indvdum@0
|
49 |
'LABEL' => 'FireBird',
|
|
indvdum@0
|
50 |
'SCHEMA' => 'firebird',
|
|
indvdum@0
|
51 |
'MODULE' => 'interbase',
|
|
indvdum@0
|
52 |
'DELIM' => ';;',
|
|
indvdum@0
|
53 |
'COMMENTS' => 'remove_remarks',
|
|
indvdum@0
|
54 |
'DRIVER' => 'firebird',
|
|
indvdum@0
|
55 |
'AVAILABLE' => true,
|
|
indvdum@0
|
56 |
'2.0.x' => false,
|
|
indvdum@0
|
57 |
),
|
|
indvdum@0
|
58 |
'mysqli' => array(
|
|
indvdum@0
|
59 |
'LABEL' => 'MySQL with MySQLi Extension',
|
|
indvdum@0
|
60 |
'SCHEMA' => 'mysql_41',
|
|
indvdum@0
|
61 |
'MODULE' => 'mysqli',
|
|
indvdum@0
|
62 |
'DELIM' => ';',
|
|
indvdum@0
|
63 |
'COMMENTS' => 'remove_remarks',
|
|
indvdum@0
|
64 |
'DRIVER' => 'mysqli',
|
|
indvdum@0
|
65 |
'AVAILABLE' => true,
|
|
indvdum@0
|
66 |
'2.0.x' => true,
|
|
indvdum@0
|
67 |
),
|
|
indvdum@0
|
68 |
'mysql' => array(
|
|
indvdum@0
|
69 |
'LABEL' => 'MySQL',
|
|
indvdum@0
|
70 |
'SCHEMA' => 'mysql',
|
|
indvdum@0
|
71 |
'MODULE' => 'mysql',
|
|
indvdum@0
|
72 |
'DELIM' => ';',
|
|
indvdum@0
|
73 |
'COMMENTS' => 'remove_remarks',
|
|
indvdum@0
|
74 |
'DRIVER' => 'mysql',
|
|
indvdum@0
|
75 |
'AVAILABLE' => true,
|
|
indvdum@0
|
76 |
'2.0.x' => true,
|
|
indvdum@0
|
77 |
),
|
|
indvdum@0
|
78 |
'mssql' => array(
|
|
indvdum@0
|
79 |
'LABEL' => 'MS SQL Server 2000+',
|
|
indvdum@0
|
80 |
'SCHEMA' => 'mssql',
|
|
indvdum@0
|
81 |
'MODULE' => 'mssql',
|
|
indvdum@0
|
82 |
'DELIM' => 'GO',
|
|
indvdum@0
|
83 |
'COMMENTS' => 'remove_comments',
|
|
indvdum@0
|
84 |
'DRIVER' => 'mssql',
|
|
indvdum@0
|
85 |
'AVAILABLE' => true,
|
|
indvdum@0
|
86 |
'2.0.x' => true,
|
|
indvdum@0
|
87 |
),
|
|
indvdum@0
|
88 |
'mssql_odbc'=> array(
|
|
indvdum@0
|
89 |
'LABEL' => 'MS SQL Server [ ODBC ]',
|
|
indvdum@0
|
90 |
'SCHEMA' => 'mssql',
|
|
indvdum@0
|
91 |
'MODULE' => 'odbc',
|
|
indvdum@0
|
92 |
'DELIM' => 'GO',
|
|
indvdum@0
|
93 |
'COMMENTS' => 'remove_comments',
|
|
indvdum@0
|
94 |
'DRIVER' => 'mssql_odbc',
|
|
indvdum@0
|
95 |
'AVAILABLE' => true,
|
|
indvdum@0
|
96 |
'2.0.x' => true,
|
|
indvdum@0
|
97 |
),
|
|
indvdum@0
|
98 |
'mssqlnative' => array(
|
|
indvdum@0
|
99 |
'LABEL' => 'MS SQL Server 2005+ [ Native ]',
|
|
indvdum@0
|
100 |
'SCHEMA' => 'mssql',
|
|
indvdum@0
|
101 |
'MODULE' => 'sqlsrv',
|
|
indvdum@0
|
102 |
'DELIM' => 'GO',
|
|
indvdum@0
|
103 |
'COMMENTS' => 'remove_comments',
|
|
indvdum@0
|
104 |
'DRIVER' => 'mssqlnative',
|
|
indvdum@0
|
105 |
'AVAILABLE' => true,
|
|
indvdum@0
|
106 |
'2.0.x' => false,
|
|
indvdum@0
|
107 |
),
|
|
indvdum@0
|
108 |
'oracle' => array(
|
|
indvdum@0
|
109 |
'LABEL' => 'Oracle',
|
|
indvdum@0
|
110 |
'SCHEMA' => 'oracle',
|
|
indvdum@0
|
111 |
'MODULE' => 'oci8',
|
|
indvdum@0
|
112 |
'DELIM' => '/',
|
|
indvdum@0
|
113 |
'COMMENTS' => 'remove_comments',
|
|
indvdum@0
|
114 |
'DRIVER' => 'oracle',
|
|
indvdum@0
|
115 |
'AVAILABLE' => true,
|
|
indvdum@0
|
116 |
'2.0.x' => false,
|
|
indvdum@0
|
117 |
),
|
|
indvdum@0
|
118 |
'postgres' => array(
|
|
indvdum@0
|
119 |
'LABEL' => 'PostgreSQL 7.x/8.x',
|
|
indvdum@0
|
120 |
'SCHEMA' => 'postgres',
|
|
indvdum@0
|
121 |
'MODULE' => 'pgsql',
|
|
indvdum@0
|
122 |
'DELIM' => ';',
|
|
indvdum@0
|
123 |
'COMMENTS' => 'remove_comments',
|
|
indvdum@0
|
124 |
'DRIVER' => 'postgres',
|
|
indvdum@0
|
125 |
'AVAILABLE' => true,
|
|
indvdum@0
|
126 |
'2.0.x' => true,
|
|
indvdum@0
|
127 |
),
|
|
indvdum@0
|
128 |
'sqlite' => array(
|
|
indvdum@0
|
129 |
'LABEL' => 'SQLite',
|
|
indvdum@0
|
130 |
'SCHEMA' => 'sqlite',
|
|
indvdum@0
|
131 |
'MODULE' => 'sqlite',
|
|
indvdum@0
|
132 |
'DELIM' => ';',
|
|
indvdum@0
|
133 |
'COMMENTS' => 'remove_remarks',
|
|
indvdum@0
|
134 |
'DRIVER' => 'sqlite',
|
|
indvdum@0
|
135 |
'AVAILABLE' => true,
|
|
indvdum@0
|
136 |
'2.0.x' => false,
|
|
indvdum@0
|
137 |
),
|
|
indvdum@0
|
138 |
);
|
|
indvdum@0
|
139 |
|
|
indvdum@0
|
140 |
if ($dbms)
|
|
indvdum@0
|
141 |
{
|
|
indvdum@0
|
142 |
if (isset($available_dbms[$dbms]))
|
|
indvdum@0
|
143 |
{
|
|
indvdum@0
|
144 |
$available_dbms = array($dbms => $available_dbms[$dbms]);
|
|
indvdum@0
|
145 |
}
|
|
indvdum@0
|
146 |
else
|
|
indvdum@0
|
147 |
{
|
|
indvdum@0
|
148 |
return array();
|
|
indvdum@0
|
149 |
}
|
|
indvdum@0
|
150 |
}
|
|
indvdum@0
|
151 |
|
|
indvdum@0
|
152 |
// now perform some checks whether they are really available
|
|
indvdum@0
|
153 |
foreach ($available_dbms as $db_name => $db_ary)
|
|
indvdum@0
|
154 |
{
|
|
indvdum@0
|
155 |
if ($only_20x_options && !$db_ary['2.0.x'])
|
|
indvdum@0
|
156 |
{
|
|
indvdum@0
|
157 |
if ($return_unavailable)
|
|
indvdum@0
|
158 |
{
|
|
indvdum@0
|
159 |
$available_dbms[$db_name]['AVAILABLE'] = false;
|
|
indvdum@0
|
160 |
}
|
|
indvdum@0
|
161 |
else
|
|
indvdum@0
|
162 |
{
|
|
indvdum@0
|
163 |
unset($available_dbms[$db_name]);
|
|
indvdum@0
|
164 |
}
|
|
indvdum@0
|
165 |
continue;
|
|
indvdum@0
|
166 |
}
|
|
indvdum@0
|
167 |
|
|
indvdum@0
|
168 |
$dll = $db_ary['MODULE'];
|
|
indvdum@0
|
169 |
|
|
indvdum@0
|
170 |
if (!@extension_loaded($dll))
|
|
indvdum@0
|
171 |
{
|
|
indvdum@0
|
172 |
if (!can_load_dll($dll))
|
|
indvdum@0
|
173 |
{
|
|
indvdum@0
|
174 |
if ($return_unavailable)
|
|
indvdum@0
|
175 |
{
|
|
indvdum@0
|
176 |
$available_dbms[$db_name]['AVAILABLE'] = false;
|
|
indvdum@0
|
177 |
}
|
|
indvdum@0
|
178 |
else
|
|
indvdum@0
|
179 |
{
|
|
indvdum@0
|
180 |
unset($available_dbms[$db_name]);
|
|
indvdum@0
|
181 |
}
|
|
indvdum@0
|
182 |
continue;
|
|
indvdum@0
|
183 |
}
|
|
indvdum@0
|
184 |
}
|
|
indvdum@0
|
185 |
$any_db_support = true;
|
|
indvdum@0
|
186 |
}
|
|
indvdum@0
|
187 |
|
|
indvdum@0
|
188 |
if ($return_unavailable)
|
|
indvdum@0
|
189 |
{
|
|
indvdum@0
|
190 |
$available_dbms['ANY_DB_SUPPORT'] = $any_db_support;
|
|
indvdum@0
|
191 |
}
|
|
indvdum@0
|
192 |
return $available_dbms;
|
|
indvdum@0
|
193 |
}
|
|
indvdum@0
|
194 |
|
|
indvdum@0
|
195 |
/**
|
|
indvdum@0
|
196 |
* Generate the drop down of available database options
|
|
indvdum@0
|
197 |
*/
|
|
indvdum@0
|
198 |
function dbms_select($default = '', $only_20x_options = false)
|
|
indvdum@0
|
199 |
{
|
|
indvdum@0
|
200 |
global $lang;
|
|
indvdum@0
|
201 |
|
|
indvdum@0
|
202 |
$available_dbms = get_available_dbms(false, false, $only_20x_options);
|
|
indvdum@0
|
203 |
$dbms_options = '';
|
|
indvdum@0
|
204 |
foreach ($available_dbms as $dbms_name => $details)
|
|
indvdum@0
|
205 |
{
|
|
indvdum@0
|
206 |
$selected = ($dbms_name == $default) ? ' selected="selected"' : '';
|
|
indvdum@0
|
207 |
$dbms_options .= '<option value="' . $dbms_name . '"' . $selected .'>' . $lang['DLL_' . strtoupper($dbms_name)] . '</option>';
|
|
indvdum@0
|
208 |
}
|
|
indvdum@0
|
209 |
return $dbms_options;
|
|
indvdum@0
|
210 |
}
|
|
indvdum@0
|
211 |
|
|
indvdum@0
|
212 |
/**
|
|
indvdum@0
|
213 |
* Get tables of a database
|
|
indvdum@0
|
214 |
*
|
|
indvdum@0
|
215 |
* @deprecated
|
|
indvdum@0
|
216 |
*/
|
|
indvdum@0
|
217 |
function get_tables(&$db)
|
|
indvdum@0
|
218 |
{
|
|
indvdum@0
|
219 |
if (!class_exists('phpbb_db_tools'))
|
|
indvdum@0
|
220 |
{
|
|
indvdum@0
|
221 |
global $phpbb_root_path, $phpEx;
|
|
indvdum@0
|
222 |
require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
|
|
indvdum@0
|
223 |
}
|
|
indvdum@0
|
224 |
|
|
indvdum@0
|
225 |
$db_tools = new phpbb_db_tools($db);
|
|
indvdum@0
|
226 |
|
|
indvdum@0
|
227 |
return $db_tools->sql_list_tables();
|
|
indvdum@0
|
228 |
}
|
|
indvdum@0
|
229 |
|
|
indvdum@0
|
230 |
/**
|
|
indvdum@0
|
231 |
* Used to test whether we are able to connect to the database the user has specified
|
|
indvdum@0
|
232 |
* and identify any problems (eg there are already tables with the names we want to use
|
|
indvdum@0
|
233 |
* @param array $dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()}
|
|
indvdum@0
|
234 |
* necessary extensions should be loaded already
|
|
indvdum@0
|
235 |
*/
|
|
indvdum@0
|
236 |
function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport, $prefix_may_exist = false, $load_dbal = true, $unicode_check = true)
|
|
indvdum@0
|
237 |
{
|
|
indvdum@0
|
238 |
global $phpbb_root_path, $phpEx, $config, $lang;
|
|
indvdum@0
|
239 |
|
|
indvdum@0
|
240 |
$dbms = $dbms_details['DRIVER'];
|
|
indvdum@0
|
241 |
|
|
indvdum@0
|
242 |
if ($load_dbal)
|
|
indvdum@0
|
243 |
{
|
|
indvdum@0
|
244 |
// Include the DB layer
|
|
indvdum@0
|
245 |
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
|
|
indvdum@0
|
246 |
}
|
|
indvdum@0
|
247 |
|
|
indvdum@0
|
248 |
// Instantiate it and set return on error true
|
|
indvdum@0
|
249 |
$sql_db = 'dbal_' . $dbms;
|
|
indvdum@0
|
250 |
$db = new $sql_db();
|
|
indvdum@0
|
251 |
$db->sql_return_on_error(true);
|
|
indvdum@0
|
252 |
|
|
indvdum@0
|
253 |
// Check that we actually have a database name before going any further.....
|
|
indvdum@0
|
254 |
if ($dbms_details['DRIVER'] != 'sqlite' && $dbms_details['DRIVER'] != 'oracle' && $dbname === '')
|
|
indvdum@0
|
255 |
{
|
|
indvdum@0
|
256 |
$error[] = $lang['INST_ERR_DB_NO_NAME'];
|
|
indvdum@0
|
257 |
return false;
|
|
indvdum@0
|
258 |
}
|
|
indvdum@0
|
259 |
|
|
indvdum@0
|
260 |
// Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea
|
|
indvdum@0
|
261 |
if ($dbms_details['DRIVER'] == 'sqlite' && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
|
|
indvdum@0
|
262 |
{
|
|
indvdum@0
|
263 |
$error[] = $lang['INST_ERR_DB_FORUM_PATH'];
|
|
indvdum@0
|
264 |
return false;
|
|
indvdum@0
|
265 |
}
|
|
indvdum@0
|
266 |
|
|
indvdum@0
|
267 |
// Check the prefix length to ensure that index names are not too long and does not contain invalid characters
|
|
indvdum@0
|
268 |
switch ($dbms_details['DRIVER'])
|
|
indvdum@0
|
269 |
{
|
|
indvdum@0
|
270 |
case 'mysql':
|
|
indvdum@0
|
271 |
case 'mysqli':
|
|
indvdum@0
|
272 |
if (strspn($table_prefix, '-./\\') !== 0)
|
|
indvdum@0
|
273 |
{
|
|
indvdum@0
|
274 |
$error[] = $lang['INST_ERR_PREFIX_INVALID'];
|
|
indvdum@0
|
275 |
return false;
|
|
indvdum@0
|
276 |
}
|
|
indvdum@0
|
277 |
|
|
indvdum@0
|
278 |
// no break;
|
|
indvdum@0
|
279 |
|
|
indvdum@0
|
280 |
case 'postgres':
|
|
indvdum@0
|
281 |
$prefix_length = 36;
|
|
indvdum@0
|
282 |
break;
|
|
indvdum@0
|
283 |
|
|
indvdum@0
|
284 |
case 'mssql':
|
|
indvdum@0
|
285 |
case 'mssql_odbc':
|
|
indvdum@0
|
286 |
case 'mssqlnative':
|
|
indvdum@0
|
287 |
$prefix_length = 90;
|
|
indvdum@0
|
288 |
break;
|
|
indvdum@0
|
289 |
|
|
indvdum@0
|
290 |
case 'sqlite':
|
|
indvdum@0
|
291 |
$prefix_length = 200;
|
|
indvdum@0
|
292 |
break;
|
|
indvdum@0
|
293 |
|
|
indvdum@0
|
294 |
case 'firebird':
|
|
indvdum@0
|
295 |
case 'oracle':
|
|
indvdum@0
|
296 |
$prefix_length = 6;
|
|
indvdum@0
|
297 |
break;
|
|
indvdum@0
|
298 |
}
|
|
indvdum@0
|
299 |
|
|
indvdum@0
|
300 |
if (strlen($table_prefix) > $prefix_length)
|
|
indvdum@0
|
301 |
{
|
|
indvdum@0
|
302 |
$error[] = sprintf($lang['INST_ERR_PREFIX_TOO_LONG'], $prefix_length);
|
|
indvdum@0
|
303 |
return false;
|
|
indvdum@0
|
304 |
}
|
|
indvdum@0
|
305 |
|
|
indvdum@0
|
306 |
// Try and connect ...
|
|
indvdum@0
|
307 |
if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true)))
|
|
indvdum@0
|
308 |
{
|
|
indvdum@0
|
309 |
$db_error = $db->sql_error();
|
|
indvdum@0
|
310 |
$error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . (($db_error['message']) ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']);
|
|
indvdum@0
|
311 |
}
|
|
indvdum@0
|
312 |
else
|
|
indvdum@0
|
313 |
{
|
|
indvdum@0
|
314 |
// Likely matches for an existing phpBB installation
|
|
indvdum@0
|
315 |
if (!$prefix_may_exist)
|
|
indvdum@0
|
316 |
{
|
|
indvdum@0
|
317 |
$temp_prefix = strtolower($table_prefix);
|
|
indvdum@0
|
318 |
$table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users');
|
|
indvdum@0
|
319 |
|
|
indvdum@0
|
320 |
$tables = get_tables($db);
|
|
indvdum@0
|
321 |
$tables = array_map('strtolower', $tables);
|
|
indvdum@0
|
322 |
$table_intersect = array_intersect($tables, $table_ary);
|
|
indvdum@0
|
323 |
|
|
indvdum@0
|
324 |
if (sizeof($table_intersect))
|
|
indvdum@0
|
325 |
{
|
|
indvdum@0
|
326 |
$error[] = $lang['INST_ERR_PREFIX'];
|
|
indvdum@0
|
327 |
}
|
|
indvdum@0
|
328 |
}
|
|
indvdum@0
|
329 |
|
|
indvdum@0
|
330 |
// Make sure that the user has selected a sensible DBAL for the DBMS actually installed
|
|
indvdum@0
|
331 |
switch ($dbms_details['DRIVER'])
|
|
indvdum@0
|
332 |
{
|
|
indvdum@0
|
333 |
case 'mysqli':
|
|
indvdum@0
|
334 |
if (version_compare(mysqli_get_server_info($db->db_connect_id), '4.1.3', '<'))
|
|
indvdum@0
|
335 |
{
|
|
indvdum@0
|
336 |
$error[] = $lang['INST_ERR_DB_NO_MYSQLI'];
|
|
indvdum@0
|
337 |
}
|
|
indvdum@0
|
338 |
break;
|
|
indvdum@0
|
339 |
|
|
indvdum@0
|
340 |
case 'sqlite':
|
|
indvdum@0
|
341 |
if (version_compare(sqlite_libversion(), '2.8.2', '<'))
|
|
indvdum@0
|
342 |
{
|
|
indvdum@0
|
343 |
$error[] = $lang['INST_ERR_DB_NO_SQLITE'];
|
|
indvdum@0
|
344 |
}
|
|
indvdum@0
|
345 |
break;
|
|
indvdum@0
|
346 |
|
|
indvdum@0
|
347 |
case 'firebird':
|
|
indvdum@0
|
348 |
// check the version of FB, use some hackery if we can't get access to the server info
|
|
indvdum@0
|
349 |
if ($db->service_handle !== false && function_exists('ibase_server_info'))
|
|
indvdum@0
|
350 |
{
|
|
indvdum@0
|
351 |
$val = @ibase_server_info($db->service_handle, IBASE_SVC_SERVER_VERSION);
|
|
indvdum@0
|
352 |
preg_match('#V([\d.]+)#', $val, $match);
|
|
indvdum@0
|
353 |
if ($match[1] < 2)
|
|
indvdum@0
|
354 |
{
|
|
indvdum@0
|
355 |
$error[] = $lang['INST_ERR_DB_NO_FIREBIRD'];
|
|
indvdum@0
|
356 |
}
|
|
indvdum@0
|
357 |
$db_info = @ibase_db_info($db->service_handle, $dbname, IBASE_STS_HDR_PAGES);
|
|
indvdum@0
|
358 |
|
|
indvdum@0
|
359 |
preg_match('/^\\s*Page size\\s*(\\d+)/m', $db_info, $regs);
|
|
indvdum@0
|
360 |
$page_size = intval($regs[1]);
|
|
indvdum@0
|
361 |
if ($page_size < 8192)
|
|
indvdum@0
|
362 |
{
|
|
indvdum@0
|
363 |
$error[] = $lang['INST_ERR_DB_NO_FIREBIRD_PS'];
|
|
indvdum@0
|
364 |
}
|
|
indvdum@0
|
365 |
}
|
|
indvdum@0
|
366 |
else
|
|
indvdum@0
|
367 |
{
|
|
indvdum@0
|
368 |
$sql = "SELECT *
|
|
indvdum@0
|
369 |
FROM RDB$FUNCTIONS
|
|
indvdum@0
|
370 |
WHERE RDB$SYSTEM_FLAG IS NULL
|
|
indvdum@0
|
371 |
AND RDB$FUNCTION_NAME = 'CHAR_LENGTH'";
|
|
indvdum@0
|
372 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
373 |
$row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
374 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
375 |
|
|
indvdum@0
|
376 |
// if its a UDF, its too old
|
|
indvdum@0
|
377 |
if ($row)
|
|
indvdum@0
|
378 |
{
|
|
indvdum@0
|
379 |
$error[] = $lang['INST_ERR_DB_NO_FIREBIRD'];
|
|
indvdum@0
|
380 |
}
|
|
indvdum@0
|
381 |
else
|
|
indvdum@0
|
382 |
{
|
|
indvdum@0
|
383 |
$sql = 'SELECT 1 FROM RDB$DATABASE
|
|
indvdum@0
|
384 |
WHERE BIN_AND(10, 1) = 0';
|
|
indvdum@0
|
385 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
386 |
if (!$result) // This can only fail if BIN_AND is not defined
|
|
indvdum@0
|
387 |
{
|
|
indvdum@0
|
388 |
$error[] = $lang['INST_ERR_DB_NO_FIREBIRD'];
|
|
indvdum@0
|
389 |
}
|
|
indvdum@0
|
390 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
391 |
}
|
|
indvdum@0
|
392 |
|
|
indvdum@0
|
393 |
// Setup the stuff for our random table
|
|
indvdum@0
|
394 |
$char_array = array_merge(range('A', 'Z'), range('0', '9'));
|
|
indvdum@0
|
395 |
$char_len = mt_rand(7, 9);
|
|
indvdum@0
|
396 |
$char_array_len = sizeof($char_array) - 1;
|
|
indvdum@0
|
397 |
|
|
indvdum@0
|
398 |
$final = '';
|
|
indvdum@0
|
399 |
|
|
indvdum@0
|
400 |
for ($i = 0; $i < $char_len; $i++)
|
|
indvdum@0
|
401 |
{
|
|
indvdum@0
|
402 |
$final .= $char_array[mt_rand(0, $char_array_len)];
|
|
indvdum@0
|
403 |
}
|
|
indvdum@0
|
404 |
|
|
indvdum@0
|
405 |
// Create some random table
|
|
indvdum@0
|
406 |
$sql = 'CREATE TABLE ' . $final . " (
|
|
indvdum@0
|
407 |
FIELD1 VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE,
|
|
indvdum@0
|
408 |
FIELD2 INTEGER DEFAULT 0 NOT NULL);";
|
|
indvdum@0
|
409 |
$db->sql_query($sql);
|
|
indvdum@0
|
410 |
|
|
indvdum@0
|
411 |
// Create an index that should fail if the page size is less than 8192
|
|
indvdum@0
|
412 |
$sql = 'CREATE INDEX ' . $final . ' ON ' . $final . '(FIELD1, FIELD2);';
|
|
indvdum@0
|
413 |
$db->sql_query($sql);
|
|
indvdum@0
|
414 |
|
|
indvdum@0
|
415 |
if (ibase_errmsg() !== false)
|
|
indvdum@0
|
416 |
{
|
|
indvdum@0
|
417 |
$error[] = $lang['INST_ERR_DB_NO_FIREBIRD_PS'];
|
|
indvdum@0
|
418 |
}
|
|
indvdum@0
|
419 |
else
|
|
indvdum@0
|
420 |
{
|
|
indvdum@0
|
421 |
// Kill the old table
|
|
indvdum@0
|
422 |
$db->sql_query('DROP TABLE ' . $final . ';');
|
|
indvdum@0
|
423 |
}
|
|
indvdum@0
|
424 |
unset($final);
|
|
indvdum@0
|
425 |
}
|
|
indvdum@0
|
426 |
break;
|
|
indvdum@0
|
427 |
|
|
indvdum@0
|
428 |
case 'oracle':
|
|
indvdum@0
|
429 |
if ($unicode_check)
|
|
indvdum@0
|
430 |
{
|
|
indvdum@0
|
431 |
$sql = "SELECT *
|
|
indvdum@0
|
432 |
FROM NLS_DATABASE_PARAMETERS
|
|
indvdum@0
|
433 |
WHERE PARAMETER = 'NLS_RDBMS_VERSION'
|
|
indvdum@0
|
434 |
OR PARAMETER = 'NLS_CHARACTERSET'";
|
|
indvdum@0
|
435 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
436 |
|
|
indvdum@0
|
437 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
438 |
{
|
|
indvdum@0
|
439 |
$stats[$row['parameter']] = $row['value'];
|
|
indvdum@0
|
440 |
}
|
|
indvdum@0
|
441 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
442 |
|
|
indvdum@0
|
443 |
if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8')
|
|
indvdum@0
|
444 |
{
|
|
indvdum@0
|
445 |
$error[] = $lang['INST_ERR_DB_NO_ORACLE'];
|
|
indvdum@0
|
446 |
}
|
|
indvdum@0
|
447 |
}
|
|
indvdum@0
|
448 |
break;
|
|
indvdum@0
|
449 |
|
|
indvdum@0
|
450 |
case 'postgres':
|
|
indvdum@0
|
451 |
if ($unicode_check)
|
|
indvdum@0
|
452 |
{
|
|
indvdum@0
|
453 |
$sql = "SHOW server_encoding;";
|
|
indvdum@0
|
454 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
455 |
$row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
456 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
457 |
|
|
indvdum@0
|
458 |
if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8')
|
|
indvdum@0
|
459 |
{
|
|
indvdum@0
|
460 |
$error[] = $lang['INST_ERR_DB_NO_POSTGRES'];
|
|
indvdum@0
|
461 |
}
|
|
indvdum@0
|
462 |
}
|
|
indvdum@0
|
463 |
break;
|
|
indvdum@0
|
464 |
}
|
|
indvdum@0
|
465 |
|
|
indvdum@0
|
466 |
}
|
|
indvdum@0
|
467 |
|
|
indvdum@0
|
468 |
if ($error_connect && (!isset($error) || !sizeof($error)))
|
|
indvdum@0
|
469 |
{
|
|
indvdum@0
|
470 |
return true;
|
|
indvdum@0
|
471 |
}
|
|
indvdum@0
|
472 |
return false;
|
|
indvdum@0
|
473 |
}
|
|
indvdum@0
|
474 |
|
|
indvdum@0
|
475 |
/**
|
|
indvdum@0
|
476 |
* remove_remarks will strip the sql comment lines out of an uploaded sql file
|
|
indvdum@0
|
477 |
*/
|
|
indvdum@0
|
478 |
function remove_remarks(&$sql)
|
|
indvdum@0
|
479 |
{
|
|
indvdum@0
|
480 |
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
|
|
indvdum@0
|
481 |
}
|
|
indvdum@0
|
482 |
|
|
indvdum@0
|
483 |
/**
|
|
indvdum@0
|
484 |
* split_sql_file will split an uploaded sql file into single sql statements.
|
|
indvdum@0
|
485 |
* Note: expects trim() to have already been run on $sql.
|
|
indvdum@0
|
486 |
*/
|
|
indvdum@0
|
487 |
function split_sql_file($sql, $delimiter)
|
|
indvdum@0
|
488 |
{
|
|
indvdum@0
|
489 |
$sql = str_replace("\r" , '', $sql);
|
|
indvdum@0
|
490 |
$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
|
|
indvdum@0
|
491 |
|
|
indvdum@0
|
492 |
$data = array_map('trim', $data);
|
|
indvdum@0
|
493 |
|
|
indvdum@0
|
494 |
// The empty case
|
|
indvdum@0
|
495 |
$end_data = end($data);
|
|
indvdum@0
|
496 |
|
|
indvdum@0
|
497 |
if (empty($end_data))
|
|
indvdum@0
|
498 |
{
|
|
indvdum@0
|
499 |
unset($data[key($data)]);
|
|
indvdum@0
|
500 |
}
|
|
indvdum@0
|
501 |
|
|
indvdum@0
|
502 |
return $data;
|
|
indvdum@0
|
503 |
}
|
|
indvdum@0
|
504 |
|
|
indvdum@0
|
505 |
/**
|
|
indvdum@0
|
506 |
* For replacing {L_*} strings with preg_replace_callback
|
|
indvdum@0
|
507 |
*/
|
|
indvdum@0
|
508 |
function adjust_language_keys_callback($matches)
|
|
indvdum@0
|
509 |
{
|
|
indvdum@0
|
510 |
if (!empty($matches[1]))
|
|
indvdum@0
|
511 |
{
|
|
indvdum@0
|
512 |
global $lang, $db;
|
|
indvdum@0
|
513 |
|
|
indvdum@0
|
514 |
return (!empty($lang[$matches[1]])) ? $db->sql_escape($lang[$matches[1]]) : $db->sql_escape($matches[1]);
|
|
indvdum@0
|
515 |
}
|
|
indvdum@0
|
516 |
}
|
|
indvdum@0
|
517 |
|
|
indvdum@0
|
518 |
?> |