1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-19 15:17:16 +01:00

Few more changes ... now look for (possible) existence of existing tables with same prefix, warn if appropriate, output fatal error on other SQL failures

git-svn-id: file:///svn/phpbb/trunk@4136 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-06-15 18:10:59 +00:00
parent dc3ed2e128
commit b87efc8994
2 changed files with 151 additions and 80 deletions

View File

@ -251,19 +251,7 @@ else if (isset($_POST['install']))
}
}
// Include the DB layer
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
// Instantiate it and set return on error true
$db = new sql_db();
$db->sql_return_on_error(true);
// Try and connect ...
if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false)))
{
$db_error = $db->sql_error();
$error['db'][] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . (($db_error['message']) ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']);
}
connect_check_db(false, $error, $dbms, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport);
// No errors so lets do the twist
if (sizeof($error))
@ -576,24 +564,7 @@ if ($stage == 1)
}
}
// Include the DB layer
include_once($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
// Instantiate it and set return on error true
$db = new sql_db();
$db->sql_return_on_error(true);
// Try and connect ...
if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false)))
{
$db_error = $db->sql_error();
$error['db'][] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . (($db_error['message']) ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']);
}
if (!sizeof($error['db']))
{
$error['db'][] = $lang['INSTALL_DB_CONNECT'];
}
connect_check_db(true, $error, $dbms, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport);
}
@ -686,11 +657,11 @@ if ($stage == 1)
<td class="row2"><input class="post" type="text" name="admin_name" value="<?php echo ($admin_name != '') ? $admin_name : ''; ?>" /></td>
</tr>
<tr>
<td class="row1" width="50%"><b><?php echo $lang['ADMIN_EMAIL']; ?>: </b></td>
<td class="row1" width="50%"><b><?php echo $lang['CONTACT_EMAIL']; ?>: </b></td>
<td class="row2"><input class="post" type="text" name="board_email1" value="<?php echo ($board_email1 != '') ? $board_email1 : ''; ?>" /></td>
</tr>
<tr>
<td class="row1" width="50%"><b><?php echo $lang['ADMIN_EMAIL_CONFIRM']; ?>: </b></td>
<td class="row1" width="50%"><b><?php echo $lang['CONTACT_EMAIL_CONFIRM']; ?>: </b></td>
<td class="row2"><input class="post" type="text" name="board_email2" value="<?php echo ($board_email2 != '') ? $board_email2 : ''; ?>" /></td>
</tr>
<tr>
@ -1055,15 +1026,13 @@ if ($stage == 3)
@dl($available_dbms[$dbms]['MODULE'] . ".$prefix");
}
// Load the appropriate database class if not already loaded
include_once($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
// Instantiate the database
$db = new sql_db();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
// We ship the Access schema complete, we don't need to create tables nor
// populate it (at this time ... this may change). So we skip this section
if ($dbms != 'msaccess')
@ -1071,7 +1040,6 @@ if ($stage == 3)
// NOTE: trigger_error does not work here.
$db->return_on_error = true;
$ignore_tables = array();
// Ok we have the db info go ahead and read in the relevant schema
// and work on building the table
@ -1093,22 +1061,12 @@ if ($stage == 3)
$sql = trim($sql);
if (!$db->sql_query($sql))
{
// TODO
//
// This is a fudgy way of dealing with attempts at installing to a DB
// which already contains the relevant tables. Next thing to do is
// to quit back to stage 1 and inform the user that this table extension
// is already in use
$ignore_tables[] = preg_replace('#^CREATE TABLE ([a-z_]+?) .*$#is', '\1', $sql);
$error = $db->sql_error();
die($error['message']);
inst_db_error($error['message'], $sql, __LINE__, __FILE__);
}
}
unset($sql_query);
$ignore_tables = str_replace('\\|', '|', preg_quote(implode('|', $ignore_tables), '#'));
// Ok tables have been built, let's fill in the basic information
$sql_query = fread(fopen('schemas/schema_data.sql', 'r'), filesize('schemas/schema_data.sql'));
@ -1133,15 +1091,10 @@ if ($stage == 3)
foreach ($sql_query as $sql)
{
$sql = trim(str_replace('|', ';', $sql));
if ($ignore_tables != '' && preg_match('#' . $ignore_tables . '#', $sql))
{
continue;
}
if (!$db->sql_query($sql))
{
$error = $db->sql_error();
die($error['message']);
inst_db_error($error['message'], $sql, __LINE__, __FILE__);
}
}
unset($sql_query);
@ -1171,9 +1124,13 @@ if ($stage == 3)
WHERE config_name = 'script_path'",
'UPDATE ' . $table_prefix . "config
SET config_value = '" . $db->sql_escape($board_email) . "'
SET config_value = '" . $db->sql_escape($board_email1) . "'
WHERE config_name = 'board_email'",
'UPDATE ' . $table_prefix . "config
SET config_value = '" . $db->sql_escape($board_email1) . "'
WHERE config_name = 'board_contact'",
'UPDATE ' . $table_prefix . "config
SET config_value = '" . $db->sql_escape($server_name) . "'
WHERE config_name = 'cookie_domain'",
@ -1215,15 +1172,11 @@ if ($stage == 3)
foreach ($sql_ary as $sql)
{
$sql = trim(str_replace('|', ';', $sql));
if ($ignore_tables != '' && preg_match('#' . $ignore_tables . '#i', $sql))
{
continue;
}
if (!$db->sql_query($sql))
{
$error = $db->sql_error();
die($error['message']);
inst_db_error($error['message'], $sql, __LINE__, __FILE__);
}
}
@ -1264,6 +1217,8 @@ if ($stage == 4)
<?php
$db->sql_close();
inst_page_footer();
exit;
@ -1326,16 +1281,42 @@ td.cat { background-image: url('../adm/images/cellpic1.gif') }
}
// Output page -> footer
function inst_page_footer()
function inst_db_error($error, $sql, $line, $file)
{
global $lang;
global $lang, $db;
inst_page_header();
?>
<div class="copyright" align="center">Powered by phpBB 2.2 &copy; 2003 <a href="http://www.phpbb.com/" target="_phpbb" class="copyright">phpBB Group</a></div>
<h1 style="color:red;text-align:center"><?php echo $lang['INST_ERR_FATAL']; ?></h1>
<br clear="all" />
<p><?php echo $lang['INST_ERR_FATAL_DB']; ?></p>
<p><?php echo "$file [ $line ]"; ?></p>
<p>SQL : <?php echo $sql; ?></p>
<p><b><?php echo $error; ?></b></p>
<?php
$db->sql_close();
inst_page_footer();
exit;
}
// Output page -> footer
function inst_page_footer()
{
?>
<div class="copyright" align="center">Powered by phpBB 2.2 &copy; <a href="http://www.phpbb.com/" target="_phpbb" class="copyright">phpBB Group</a>, 2003</div>
<br clear="all" /></td>
</tr>
</table>
</body>
</html>
@ -1348,7 +1329,6 @@ function inst_language_select($default = '')
global $phpbb_root_path, $phpEx;
$dir = @opendir($phpbb_root_path . 'language');
$user = array();
while ($file = readdir($dir))
{
@ -1385,6 +1365,94 @@ function can_load_dll($dll)
return ((@ini_get('enable_dl') || strtolower(@ini_get('enable_dl')) == 'on') && (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') && @dl($dll . ".$suffix")) ? true : false;
}
function connect_check_db($error_connect, &$error, &$dbms, &$table_prefix, &$dbhost, &$dbuser, &$dbpasswd, &$dbname, &$dbport)
{
global $phpbb_root_path, $phpEx, $config, $lang;
// Include the DB layer
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
// Instantiate it and set return on error true
$db = new sql_db();
$db->sql_return_on_error(true);
// Try and connect ...
if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false)))
{
$db_error = $db->sql_error();
$error['db'][] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . (($db_error['message']) ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']);
}
else
{
switch ($dbms)
{
case 'mysql':
case 'mysql4':
$sql = "SHOW TABLES";
$field = "Tables_in_{$dbname}";
break;
case 'mssql':
case 'mssql-odbc':
$sql = "SELECT name
FROM sysobjects
WHERE type='U'";
$field = "name";
break;
case 'msaccess':
$sql = 'SELECT * FROM MSysObjects
WHERE Type = 1
AND Name Not Like "MSys*"';
$field = "Name";
break;
case 'postgres':
$sql = "SELECT relname
FROM pg_class
WHERE relkind = 'r'
AND relname NOT LIKE 'pg\_%'";
$field = "relname";
break;
case 'firebird':
$sql = 'SELECT rdb$relation_name
FROM rdb$relations
WHERE rdb$view_source is null
AND rdb$system_flag = 0';
$field = 'rdb$relation_name';
break;
}
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
// Likely matches for an existing phpBB installation
$table_ary = array($table_prefix . 'attachments', $table_prefix . 'config', $table_prefix . 'sessions', $table_prefix . 'topics', $table_prefix . 'users');
do
{
// All phpBB installations will at least have config else it won't
// work
if (in_array($row[$field], $table_ary))
{
$error['db'][] = $lang['INST_ERR_PREFIX'];
break;
}
}
while ($row = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
$db->sql_close();
}
if ($error_connect && !sizeof($error['db']))
{
$error['db'][] = $lang['INSTALL_DB_CONNECT'];
}
}
//
// FUNCTIONS
// ---------

View File

@ -1107,28 +1107,29 @@ $lang = array_merge($lang, array(
'INITIAL_CONFIG_EXPLAIN'=> 'Now that install has determined your server can run phpBB you need to supply some specific information. If you do not know how to connect to your database please contact your hosting provider (in the first instance) or use the phpBB support forums. When entering data please ensure you check it thoroughly before continuing.',
'ADMIN_CONFIG' => 'Admin Configuration',
'DEFAULT_LANG' => 'Default board language',
'ADMIN_USERNAME' => 'Administrator Username',
'ADMIN_EMAIL_CONFIRM' => 'Confirm Admin Email Address',
'ADMIN_PASSWORD' => 'Administrator Password',
'ADMIN_PASSWORD_CONFIRM'=> 'Confirm Administrator Password',
'ADMIN_USERNAME' => 'Administrator username',
'CONTACT_EMAIL' => 'Contact email address',
'CONTACT_EMAIL_CONFIRM' => 'Confirm contact email',
'ADMIN_PASSWORD' => 'Administrator password',
'ADMIN_PASSWORD_CONFIRM'=> 'Confirm administrator password',
'DB_CONFIG' => 'Database Configuration',
'DBMS' => 'Database Type',
'DB_HOST' => 'Database Server Hostname or DSN',
'DBMS' => 'Database type',
'DB_HOST' => 'Database server hostname or DSN',
'DB_HOST_EXPLAIN' => 'DSN stands for Data Source Name and is relevant only for ODBC installs.',
'DB_PORT' => 'Database Server Port',
'DB_PORT' => 'Database server port',
'DB_PORT_EXPLAIN' => 'Leave this blank unless you know the server operates on a non-standard port.',
'DB_NAME' => 'Your Database Name',
'DB_USERNAME' => 'Database Username',
'DB_PASSWORD' => 'Database Password',
'DB_NAME' => 'Database name',
'DB_USERNAME' => 'Database username',
'DB_PASSWORD' => 'Database password',
'TABLE_PREFIX' => 'Prefix for tables in database',
'DB_TEST' => 'Test Connection',
'INSTALL_DB_CONNECT'=> 'Successfull Connection',
'SERVER_CONFIG' => 'Server Configuration',
'SERVER_NAME' => 'Domain Name',
'SERVER_NAME' => 'Domain name',
'SERVER_NAME_EXPLAIN' => 'The domain name this board runs from',
'SCRIPT_PATH' => 'Script path',
'SCRIPT_PATH_EXPLAIN' => 'The path where phpBB2 is located relative to the domain name',
'SERVER_PORT' => 'Server Port',
'SERVER_PORT' => 'Server port',
'SERVER_PORT_EXPLAIN' => 'The port your server is running on, usually 80, only change if different',
'INSTALL_START' => 'Start Install',
@ -1152,15 +1153,17 @@ $lang = array_merge($lang, array(
'INSTALL_CONGRATS_EXPLAIN' => 'You have now successfully installed phpBB 2.2. Clicking the button below will take you to your Administration Control Panel (ACP). Take some time to examine the options available to you. Remember that help is available online via the Userguide and the phpBB support forums, see the %sREADME%s for further information.',
'INSTALL_LOGIN' => 'Login',
'INST_ERR_FATAL' => 'Fatal installation error',
'INST_ERR_MISSING_DATA' => 'You must fill out all fields in this block',
'INST_ERR_NO_DB' => 'Cannot load the PHP module for the selected database type',
'INST_ERR_EMAIL_MISMATCH' => 'The emails you entered did not match.',
'INST_ERR_PASSWORD_MISMATCH'=> 'The passwords you entered did not match.',
'INST_ERR_DB_CONNECT' => 'Could not connect to the database, see error message below',
'INST_ERR_DB_NO_ERROR' => 'No error message given',
'INST_ERR_DB_NO_ERROR' => 'No error message given',
'INST_ERR_PREFIX' => 'Tables with the specified prefix already exist, please choose an alternative.',
'INST_ERR_FATAL_DB' => 'A fatal and unrecoverable database error has occured. This may be because the specified user does not have appropriate rights to CREATE TABLES or INSERT data, etc. Further information may be given below. Please contact your hosting provider in the first instance or the support forums of phpBB for further assistance.',
'INST_ERR_FTP_PATH' => 'Could not change to the given directory, please check the path.',
'INST_ERR_FTP_LOGIN' => 'Could not login to ftp server, check your username and password',
));
?>