function startProcess($db) { $businessComfirmUrl = Yii::app()->params['orderUrl'] . "update/order/business-confirm-order"; $time = time(); $formatTime = date('Y-m-d H:i:s', $time); try { //查找订单 $payTime = $time - 1800; $sql = "SELECT b.business_id,o.order_sn from " . get_tables('business_info') . " as b left join " . get_tables('order_info') . " as o on b.business_id=o.business_id WHERE b.express_type in (2, 11, 12) and o.order_status=1 and o.express_type > 0 and o.pay_time <= " . $payTime . " LIMIT 100"; $data = $db->createCommand($sql)->queryAll(); if (!empty($data)) { foreach ($data as $k => $v) { $post = ['business_id' => $v['business_id'], 'order_sn' => $v['order_sn'], 'user_id' => 1, 'user_name' => 'jiaoben', 'source' => 'autoStockUp']; $return = curlPost($businessComfirmUrl, $post); if ($return['code'] != 0) { addLog("data:" . json_encode($return, JSON_UNESCAPED_UNICODE) . '|time:' . $formatTime); echo $v['order_sn'] . ":fail" . "\r\n"; } else { echo $v['order_sn'] . ":success" . "\r\n"; } } echo "data update:" . count($data) . "\r\n"; } else { echo "no data \r\n"; } echo 'finish'; } catch (Exception $e) { $msg = "filename:autoStockUp|functionname:start_process|error:" . $e->getMessage() . "|time:" . $formatTime; echo $msg . "\r\n"; addLog($msg); } }
function del_tables($prefix) { $tables = get_tables($prefix); $query = 'drop table ' . $tables[0]; for ($i = 0; $i < count($tables); $i++) { $query .= "," . $tables[$i]; } $query .= ";"; mysql_query($query); }
function drop_tables($prefix) { $tables = get_tables($prefix); $query = 'drop table `' . $tables[0] . "`"; for ($i=1; $i < count($tables); $i++) $query .= ", `" . $tables[$i] . "`"; $query .= ";"; print $query; mysql_query($query); }
<?php // Purpose working with data (import/export, type in, ...) // Author Lutz Brueckner <*****@*****.**> // Copyright (c) 2000-2006 by Lutz Brueckner, // published under the terms of the GNU General Public Licence v.2, // see file LICENCE for details require './inc/script_start.inc.php'; require './inc/foreign_keys.inc.php'; require './inc/DataForm.php'; // // setup $s_tables[] and $s_fields[] if necessary // if ($s_connected && $s_tables_valid == FALSE) { include_once './inc/get_tables.inc.php'; if (get_tables($dbhandle)) { $s_tables_valid = TRUE; } } require './inc/handle_watchtable.inc.php'; // // handle foreign key lookup configuration // $customize_changed = FALSE; if (isset($_POST['dt_column_config_save'])) { $column = get_request_data('dt_column_config_column'); $table = get_request_data('dt_column_config_table'); $fk_column = get_request_data('dt_column_config_fk_column'); if ($fk_column == '') { unset($s_cust['fk_lookups'][$table][$column]); if (empty($s_cust['fk_lookups'][$table])) {
function export_db($is_backup = false) { global $db, $db_host, $db_user, $db_pass, $db_name, $db_port; $stime = microtime(true); if ($is_backup) { $output_file = str_replace('\\', '/', getcwd()) . "/backup/" . date("Y-m-d_H-i-s") . ".php"; } else { $changes = get_changes(); $i = 0; while (true) { $i += 1; $file_name = date("Y-m-d") . "-" . sprintf("%02d", $i); $ver = (int) str_replace('-', '', $file_name); if (array_key_exists($ver, $changes) == false) { break; } } $output_file = str_replace('\\', '/', getcwd()) . "/changes/" . $file_name . ".dump.php"; } $file = fopen($output_file, 'c'); $tables = get_tables($db_host, $db_user, $db_pass, $db_name, $db_port); $max_length = get_max_length($tables); fwrite($file, "<?php\n\n"); fwrite($file, "echo \"\\n\\n\";\n"); fwrite($file, "\n execute(\"\n /*!40101 SET NAMES utf8 */;\n\n /*!40101 SET SQL_MODE=''*/;\n\n /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n \");\n "); foreach ($tables as $table) { if ($table == "db_version") { continue; } if ($is_backup) { echo "backup "; } else { echo "dump "; } echo $table . " "; $dots = generate_char($max_length, strlen($table), '.'); echo $dots . "......... "; $sql = get_create_table_sql($db, $table); fwrite($file, 'if ($db_version == 0)' . "\n{\n"); fwrite($file, " echo \" " . $table . " " . $dots . "......... \";\n\n"); fwrite($file, " execute(\"\n"); fwrite($file, $sql); fwrite($file, "\n\");\n\n"); fwrite($file, " echo \"[created]\\n\"; \n"); fwrite($file, "}\n\n"); if ($is_backup == false && strpos($table, "player") === 0) { echo "[ignore]\n"; continue; } $fields = get_table_fields($db, $table); $sql = get_insert_into_sql($db, $table, $fields); fwrite($file, "echo \" " . $table . " " . $dots . "......... \";\n\n"); fwrite($file, "execute(\"DELETE FROM `" . $table . "`\");\n\n"); if ($sql != "") { fwrite($file, "execute(\"\n"); fwrite($file, $sql); fwrite($file, "\");\n\n"); } fwrite($file, "echo \"[loaded]\\n\"; \n"); fwrite($file, "\n"); echo "[done]\n"; } fwrite($file, "\n execute(\"\n /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n \");\n "); fwrite($file, "echo \"\\n\";\n"); fwrite($file, "?>\n"); fclose($file); if ($is_backup == false) { $sql = "UPDATE `db_version` SET `version` = " . $ver . ", `change_time` = UNIX_TIMESTAMP()"; if ($db->query($sql) === FALSE) { die("can't update db_version"); } } $etime = microtime(true); echo "\ndatabase "; if ($is_backup) { echo "backup "; } else { echo "dump "; } echo "complete in " . round($etime - $stime, 2) . "s\n"; }
/** * Used to test whether we are able to connect to the database the user has specified * and identify any problems (eg there are already tables with the names we want to use * @param array $dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()} necessary extensions should be loaded already */ 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) { global $config, $lang; $dbms = $dbms_details['DRIVER']; if ($load_dbal) { // Include the DB layer include $phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx; } // Instantiate it and set return on error true $sql_db = 'dbal_' . $dbms; $db = new $sql_db(); $db->sql_return_on_error(true); // Check that we actually have a database name before going any further..... if ($dbms_details['DRIVER'] != 'sqlite' && $dbms_details['DRIVER'] != 'oracle' && $dbname === '') { $error[] = $lang['INST_ERR_DB_NO_NAME']; return false; } // Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea if ($dbms_details['DRIVER'] == 'sqlite' && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0) { $error[] = $lang['INST_ERR_DB_FORUM_PATH']; return false; } // Check the prefix length to ensure that index names are not too long and does not contain invalid characters switch ($dbms_details['DRIVER']) { case 'mysql': case 'mysqli': if (strspn($table_prefix, '-./\\') !== 0) { $error[] = $lang['INST_ERR_PREFIX_INVALID']; return false; } break; } if (strlen($table_prefix) > $prefix_length) { $error[] = sprintf($lang['INST_ERR_PREFIX_TOO_LONG'], $prefix_length); return false; } // Try and connect ... if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true))) { $db_error = $db->sql_error(); $error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . ($db_error['message'] ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']); } else { // Likely matches for an existing phpBB installation if (!$prefix_may_exist) { $temp_prefix = strtolower($table_prefix); $table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users'); $tables = get_tables($db); $tables = array_map('strtolower', $tables); $table_intersect = array_intersect($tables, $table_ary); if (sizeof($table_intersect)) { $error[] = $lang['INST_ERR_PREFIX']; } } // Make sure that the user has selected a sensible DBAL for the DBMS actually installed switch ($dbms_details['DRIVER']) { case 'mysqli': if (version_compare(mysqli_get_server_info($db->db_connect_id), '4.1.3', '<')) { $error[] = $lang['INST_ERR_DB_NO_MYSQLI']; } break; } } if ($error_connect && (!isset($error) || !sizeof($error))) { return true; } return false; }
<link rel="stylesheet" type="text/css" href="../css/body.css" /> <style> body {font-size:80%; margin:5px;} h1 {font-size:140%} table {margin-left:40px; border-collapse:collapse} td {border:1px solid #C0C0C0; padding:2px} .grey {background-color:#EAEAEA; font-weight:bold} .nonexist {background-color:#FFC0C0} .dkred {background-color:#C00000; color:white; font-weight:bold} .err {color:red; font-weight:bold} </style> </head> <body> <?php if (isset($_POST['submit'])) { make_db_connections(); $table_list = get_tables($_POST['master_dbname'], $master_mysqli); foreach ($table_list as $table) { echo "<h1>{$table}</h1>\n"; compare_indexes($_POST['master_dbname'], $_POST['test_dbname'], $table, $master_mysqli, $test_mysqli); } } else { echo display_form(); } ?> </body> </html>
/** * Table Exists * * Check if a table exists in the DB or not * * @param string $table_name The table name to check for * * @return bool true if the table exists, false if not */ function table_exists($table_name) { $this->get_table_name($table_name); // Use sql_table_exists if available if (method_exists($this->db_tools, 'sql_table_exists')) { $roe = $this->db->return_on_error; $result = $this->db_tools->sql_table_exists($table_name); // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before if ($roe) { $this->db->sql_return_on_error(true); } return $result; } if (!function_exists('get_tables')) { global $phpbb_root_path, $phpEx; include $phpbb_root_path . 'includes/functions_install.' . $phpEx; } $tables = get_tables($this->db); if (in_array($table_name, $tables)) { return true; } else { return false; } }
function get_logtables($link) { // Create an array of the column names in the default table $query = "DESCRIBE " . DEFAULTLOGTABLE; $result = perform_query($query, $link); $defaultFieldArray = array(); while ($row = mysql_fetch_array($result)) { array_push($defaultFieldArray, $row['Field']); } // Create an array with the names of all the log tables $logTableArray = array(); $allTablesArray = get_tables($link); foreach ($allTablesArray as $value) { // Create an array of the column names in the current table $query = "DESCRIBE " . $value; $result = perform_query($query, $link); // Get the names of columns in current table $fieldArray = array(); while ($row = mysql_fetch_array($result)) { array_push($fieldArray, $row['Field']); } // If the current array is identical to the one from the // DEFAULTLOGTABLE then the name is added to the result // array. $diffArray = array_diff_assoc($defaultFieldArray, $fieldArray); if (!$diffArray) { array_push($logTableArray, $value); } } return $logTableArray; }
/** * Used to test whether we are able to connect to the database the user has specified * and identify any problems (eg there are already tables with the names we want to use * @param array $dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()} * necessary extensions should be loaded already */ 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) { global $phpbb_root_path, $phpEx, $config, $lang; $dbms = $dbms_details['DRIVER']; if ($load_dbal) { // Include the DB layer include $phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx; } // Instantiate it and set return on error true $sql_db = 'dbal_' . $dbms; $db = new $sql_db(); $db->sql_return_on_error(true); // Check that we actually have a database name before going any further..... if ($dbms_details['DRIVER'] != 'sqlite' && $dbms_details['DRIVER'] != 'oracle' && $dbname === '') { $error[] = $lang['INST_ERR_DB_NO_NAME']; return false; } // Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea if ($dbms_details['DRIVER'] == 'sqlite' && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0) { $error[] = $lang['INST_ERR_DB_FORUM_PATH']; return false; } // Check the prefix length to ensure that index names are not too long and does not contain invalid characters switch ($dbms_details['DRIVER']) { case 'mysql': case 'mysqli': if (strspn($table_prefix, '-./\\') !== 0) { $error[] = $lang['INST_ERR_PREFIX_INVALID']; return false; } // no break; // no break; case 'postgres': $prefix_length = 36; break; case 'mssql': case 'mssql_odbc': case 'mssqlnative': $prefix_length = 90; break; case 'sqlite': $prefix_length = 200; break; case 'firebird': case 'oracle': $prefix_length = 6; break; } if (strlen($table_prefix) > $prefix_length) { $error[] = sprintf($lang['INST_ERR_PREFIX_TOO_LONG'], $prefix_length); return false; } // Try and connect ... if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true))) { $db_error = $db->sql_error(); $error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . ($db_error['message'] ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']); } else { // Likely matches for an existing phpBB installation if (!$prefix_may_exist) { $temp_prefix = strtolower($table_prefix); $table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users'); $tables = get_tables($db); $tables = array_map('strtolower', $tables); $table_intersect = array_intersect($tables, $table_ary); if (sizeof($table_intersect)) { $error[] = $lang['INST_ERR_PREFIX']; } } // Make sure that the user has selected a sensible DBAL for the DBMS actually installed switch ($dbms_details['DRIVER']) { case 'mysqli': if (version_compare(mysqli_get_server_info($db->db_connect_id), '4.1.3', '<')) { $error[] = $lang['INST_ERR_DB_NO_MYSQLI']; } break; case 'sqlite': if (version_compare(sqlite_libversion(), '2.8.2', '<')) { $error[] = $lang['INST_ERR_DB_NO_SQLITE']; } break; case 'firebird': // check the version of FB, use some hackery if we can't get access to the server info if ($db->service_handle !== false && function_exists('ibase_server_info')) { $val = @ibase_server_info($db->service_handle, IBASE_SVC_SERVER_VERSION); preg_match('#V([\\d.]+)#', $val, $match); if ($match[1] < 2) { $error[] = $lang['INST_ERR_DB_NO_FIREBIRD']; } $db_info = @ibase_db_info($db->service_handle, $dbname, IBASE_STS_HDR_PAGES); preg_match('/^\\s*Page size\\s*(\\d+)/m', $db_info, $regs); $page_size = intval($regs[1]); if ($page_size < 8192) { $error[] = $lang['INST_ERR_DB_NO_FIREBIRD_PS']; } } else { $sql = "SELECT *\n\t\t\t\t\t\tFROM RDB{$FUNCTIONS}\n\t\t\t\t\t\tWHERE RDB{$SYSTEM_FLAG} IS NULL\n\t\t\t\t\t\t\tAND RDB{$FUNCTION_NAME} = 'CHAR_LENGTH'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // if its a UDF, its too old if ($row) { $error[] = $lang['INST_ERR_DB_NO_FIREBIRD']; } else { $sql = 'SELECT 1 FROM RDB$DATABASE WHERE BIN_AND(10, 1) = 0'; $result = $db->sql_query($sql); if (!$result) { $error[] = $lang['INST_ERR_DB_NO_FIREBIRD']; } $db->sql_freeresult($result); } // Setup the stuff for our random table $char_array = array_merge(range('A', 'Z'), range('0', '9')); $char_len = mt_rand(7, 9); $char_array_len = sizeof($char_array) - 1; $final = ''; for ($i = 0; $i < $char_len; $i++) { $final .= $char_array[mt_rand(0, $char_array_len)]; } // Create some random table $sql = 'CREATE TABLE ' . $final . " (\n\t\t\t\t\t\tFIELD1 VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE,\n\t\t\t\t\t\tFIELD2 INTEGER DEFAULT 0 NOT NULL);"; $db->sql_query($sql); // Create an index that should fail if the page size is less than 8192 $sql = 'CREATE INDEX ' . $final . ' ON ' . $final . '(FIELD1, FIELD2);'; $db->sql_query($sql); if (ibase_errmsg() !== false) { $error[] = $lang['INST_ERR_DB_NO_FIREBIRD_PS']; } else { // Kill the old table $db->sql_query('DROP TABLE ' . $final . ';'); } unset($final); } break; case 'oracle': if ($unicode_check) { $sql = "SELECT *\n\t\t\t\t\t\tFROM NLS_DATABASE_PARAMETERS\n\t\t\t\t\t\tWHERE PARAMETER = 'NLS_RDBMS_VERSION'\n\t\t\t\t\t\t\tOR PARAMETER = 'NLS_CHARACTERSET'"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $stats[$row['parameter']] = $row['value']; } $db->sql_freeresult($result); if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8') { $error[] = $lang['INST_ERR_DB_NO_ORACLE']; } } break; case 'postgres': if ($unicode_check) { $sql = "SHOW server_encoding;"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8') { $error[] = $lang['INST_ERR_DB_NO_POSTGRES']; } } break; } } if ($error_connect && (!isset($error) || !sizeof($error))) { return true; } return false; }
/** * Get all tables used by phpBB */ function get_phpbb_tables() { global $db, $table_prefix; static $_tables = array(); if (!empty($_tables)) { return $_tables; } if (!function_exists('get_tables')) { include PHPBB_ROOT_PATH . 'includes/functions_install.' . PHP_EXT; } // Function returns all tables in the database $all_tables = get_tables($db); // Only get tables using the phpBB prefix if (!empty($table_prefix)) { foreach ($all_tables as $table) { if (strpos($table, $table_prefix) === 0) { $_tables[] = $table; } } } else { // Use is using an empty table prefix (Bug #62537) // no way to determine the phpBB tables, in this case // we'll show everything with a warning that the tool // most likely want to trash a lot of tables '-,- global $template; $template->assign_vars(array('ERROR_MESSAGE' => user_lang('EMPTY_PREFIX_EXPLAIN'), 'ERROR_TITLE' => user_lang('EMPTY_PREFIX'))); $_tables = $all_tables; } sort($_tables); return $_tables; }
<?php require_once "data.php"; require_once "connection.php"; //получаем список таблиц из БД $tables = get_tables($mysql); if ($_POST) { $name = $_POST['tables']; $format = $_POST['formats']; get_data($name, $format, $mysql); } ?> <html lang="ru"> <head> <meta charset="UTF-8" /> <title>Работа с БД</title> <link href="style.css" rel="stylesheet" /> </head> <body> <div class="wrapper"> <div class="container"> <form action="main.php" method="post"> <select class="tables" id="tables" name="tables"> <?php echo "<option selected='selected'>Выберите таблицу</option>"; foreach ($tables as $table) { echo "<option>" . $table[0] . "</option>"; } ?> </select>
<?php require_once "main.php"; //получаем список таблиц из БД для выпадающего меню $tables = get_tables($conn); if ($_POST) { $name = $_POST['tables']; $format = $_POST['formats']; $m_format = strtolower($format); if (in_array($name, $tables)) { switch ($format) { case "CSV": create_csv($name, $conn); break; case "JSON": create_json($name, $conn); break; case "XML": create_xml($name, $conn); break; default: echo "<h3>Выберите формат файла!</h3>"; break; } //проверяем существование файла $file = DIR . $m_format . "/" . $name . "." . $m_format; if (file_exists($file)) { download_file($file); } } else { echo "<h3>Выберите таблицу из списка!</h3>";
function delete_suggestion(){ global $conn; $tablename = $_GET['tableName']; $suggestion_id = $_GET['suggestion_id']; $token = $_GET['jwt']; //we dont have to worry about checking what the result is, as as soon as it realizes we arent logged in 401 response header sent and caight by HTTP interceptor userLoggedIn($token); flush(); $accepted_tables = get_tables(); if(in_array($tablename, $accepted_tables)){ $tablename = htmlspecialchars($tablename); $suggestion_id = htmlspecialchars($suggestion_id); if($sql = $conn->prepare("DELETE FROM $tablename WHERE suggestion_id = ?")){ $sql->bind_param('s', $suggestion_id); if( !($sql->execute()) ){ echo false; } } } }
$deps = get_dependencies(OT_EXCEPTION, $dname); if (count($deps) > 0) { $message = sprintf($MESSAGES['HAVE_DEPENDENCIES'], $acc_strings['Exception'], $dname, dependencies_string($deps)); } else { if ($s_cust['askdel'] == TRUE) { $s_confirmations['exc'] = array('msg' => sprintf($MESSAGES['CONFIRM_EXC_DELETE'], $dname), 'obj' => $dname); } else { drop_exception($dname); } } } } // setup $s_tables[] and $s_fields[] if necessary if ($s_connected == TRUE && $s_tables_valid == FALSE) { include_once './inc/get_tables.inc.php'; if (get_tables()) { $s_tables_valid = TRUE; } } // // deleting of a subject is confirmed // if (isset($_POST['confirm_yes'])) { switch ($_POST['confirm_subject']) { case 'index': drop_index($s_confirmations['index']['obj']); break; case 'trigger': drop_trigger($s_confirmations['trigger']['obj']); break; case 'domain':
/** * Used to test whether we are able to connect to the database the user has specified * and identify any problems (eg there are already tables with the names we want to use * @param array $dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()} * necessary extensions should be loaded already */ function critical_connect_check_db($user, $error_connect, &$error, $dbms_details, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport, $prefix_may_exist = false, $load_dbal = true, $unicode_check = true) { // Must be globalized here for when including the DB file global $phpbb_root_path, $phpEx; if (empty($dbname)) { $error[] = $user->lang['INST_ERR_DB_NO_NAME']; return false; } $dbms = $dbms_details['SCHEMA']; if ($load_dbal) { // Include the DB layer include PHPBB_ROOT_PATH . 'phpbb/db/driver/driver_interface.' . PHP_EXT; include PHPBB_ROOT_PATH . 'phpbb/db/driver/driver.' . PHP_EXT; if ($dbms === 'mysql' || $dbms === 'mssql' || $dbms === 'mssqlnative') { $dbms_base = $dbms; if ($dbms === 'mysqli') { $dbms_base = 'mysql'; } if ($dbms === 'mssqlnative') { $dbms_base = 'mssql'; } include PHPBB_ROOT_PATH . 'phpbb/db/driver/' . $dbms_base . '_base.' . PHP_EXT; } include PHPBB_ROOT_PATH . 'phpbb/db/driver/' . $dbms . '.' . PHP_EXT; include PHPBB_ROOT_PATH . 'phpbb/db/tools.' . PHP_EXT; } // Instantiate it and set return on error true $sql_db = 'dbal_' . $dbms; switch ($dbms_details['SCHEMA']) { case 'mysql': case 'mysqli': $db = new phpbb\db\driver\mysql(); break; case 'mssql': case 'mssqlnative': case 'mssql_odbc': $db = new phpbb\db\driver\mssql(); break; case 'postgres': $db = new phpbb\db\driver\postgres(); break; case 'sqlite': case 'sqlite3': $db = new phpbb\db\driver\sqlite(); break; case 'postgres': $db = new phpbb\db\driver\postgres(); break; } $db->sql_return_on_error(true); // Check the prefix length to ensure that index names are not too long and does not contain invalid characters switch ($dbms_details['SCHEMA']) { case 'mysql': case 'mysqli': if (strspn($table_prefix, '-./\\') !== 0) { $error[] = $user->lang['INST_ERR_PREFIX_INVALID']; return false; } // no break; // no break; case 'postgres': $prefix_length = 36; break; case 'mssql': case 'mssqlnative': case 'mssql_odbc': $prefix_length = 90; break; case 'sqlite': case 'sqlite3': $prefix_length = 200; break; case 'oracle': $prefix_length = 6; break; } if (strlen($table_prefix) > $prefix_length) { $error[] = $user->lang['INST_ERR_PREFIX_TOO_LONG']; return false; } // Try and connect ... if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true))) { $db_error = $db->sql_error(); $error[] = ' ' . $user->lang['INST_ERR_DB_CONNECT'] . '' . '<br />' . ($db_error['message'] ? $db_error['message'] : '' . $user->lang['INST_ERR_DB_NO_ERROR'] . ''); } else { // Make sure that the user has selected a sensible DBAL for the DBMS actually installed switch ($dbms_details['SCHEMA']) { case 'mysqli': if (version_compare(mysqli_get_server_info($db->db_connect_id), '4.1.3', '<')) { $error[] = $user->lang['INST_ERR_DB_NO_MYSQLI']; } break; case 'sqlite': if (version_compare(sqlite_libversion(), '2.8.2', '<')) { $error[] = $user->lang['INST_ERR_DB_NO_SQLITE']; } break; case 'sqlite3': if (version_compare(sqlite_libversion(), '3.6.15', '<')) { $error[] = $user->lang['INST_ERR_DB_NO_SQLITE3']; } break; case 'postgres': if ($unicode_check) { $sql = "SHOW server_encoding;"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8') { $error[] = $user->lang['INST_ERR_DB_NO_POSTGRES']; } } break; } $tables = get_tables($db); if (!in_array($table_prefix . 'acl_options', $tables) || !in_array($table_prefix . 'config', $tables) || !in_array($table_prefix . 'forums', $tables)) { $error[] = $user->lang['CONFIG_REPAIR_NO_TABLES']; } } if ($error_connect && empty($error)) { return true; } return false; }
$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass) or show_install_err('Could not connect: ' . mysql_error()); if ($act == "silentcreateall") { mysql_query("CREATE DATABASE {$mysqldb}", $link) or show_install_err(' Query failed: ' . mysql_error($link)); foreach ($dbtables as $id) { create_table($id, $link); } } else { if ($act == "createdb") { mysql_query("CREATE DATABASE {$mysqldb}", $link) or show_install_err(' Query failed: ' . mysql_error($link)); } else { mysql_select_db($mysqldb, $link) or show_install_err('Could not select database'); if ($force_charset_in_connection) { mysql_query("SET character set {$dbencoding}", $link); } if ($act == "ct") { $curr_tables = get_tables($link); if ($curr_tables === false) { show_install_err($errors[0]); } $tocreate = array_diff(array_keys($dbtables), $curr_tables); foreach ($tocreate as $id) { create_table($id, $link); } } else { if ($act == "dt") { # comment this line to be able to drop tables show_install_err("For security reasons, removing tables is disabled by default"); foreach (array_keys($dbtables) as $id) { mysql_query("DROP TABLE IF EXISTS {$id}", $link) or show_install_err(' Query failed: ' . mysql_error($link)); } } else {
function display_options() { global $config, $db, $plugin, $template, $umil, $user; $continue = (isset($_POST['continue'])) ? true : false; $step = request_var('step', 0); $selected = request_var('items', array('' => '')); // Apply Changes to the DB? $apply_changes = true; if ($step > 0) { // Kick them if bad form key check_form_key('database_cleaner', false, append_sid(STK_INDEX, 't=database_cleaner'), true); } // include the required file for this version $version_file = preg_replace('#([^0-9]+)#', '_', $config['version']) . '.' . PHP_EXT; if (!file_exists(STK_ROOT_PATH . 'includes/database_cleaner/' . $version_file)) { trigger_error('PHPBB_VERSION_NOT_SUPPORTED'); } include(STK_ROOT_PATH . 'includes/database_cleaner/functions.' . PHP_EXT); include(STK_ROOT_PATH . 'includes/database_cleaner/' . $version_file); $cleaner = new database_cleaner_data(); $user->add_lang('acp/common'); switch ($step) { case 0 : // Display a quick intro here and make sure they know what they are doing... $template->assign_vars(array( 'S_NO_INSTRUCTIONS' => true, 'SUCCESS_TITLE' => $user->lang['DATABASE_CLEANER'], 'SUCCESS_MESSAGE' => $user->lang['DATABASE_CLEANER_WELCOME'], 'ERROR_TITLE' => ' ', 'ERROR_MESSAGE' => $user->lang['DATABASE_CLEANER_WARNING'], )); break; case 1 : // Redirect if they selected quit if (isset($_POST['quit'])) { redirect(append_sid(STK_ROOT_PATH . 'index.' . PHP_EXT)); } // Start by disabling the board if ($apply_changes) { set_config('board_disable', 1); } $template->assign_var('SUCCESS_MESSAGE', $user->lang['BOARD_DISABLE_SUCCESS']); // Find any extra tables and list them as options to remove if (!function_exists('get_tables')) { include(PHPBB_ROOT_PATH . 'includes/functions_install.' . PHP_EXT); } $existing_tables = get_tables($db); $tables = array_unique(array_merge(array_keys($cleaner->tables), $existing_tables)); sort($tables); $template->assign_block_vars('section', array( 'NAME' => $user->lang['DATABASE_TABLES'], 'TITLE' => $user->lang['DATABASE_TABLES'], )); foreach ($tables as $table) { if ((isset($cleaner->tables[$table]) && !in_array($table, $existing_tables)) || (!isset($cleaner->tables[$table]) && in_array($table, $existing_tables))) { $template->assign_block_vars('section.items', array( 'NAME' => $table, 'FIELD_NAME' => $table, 'MISSING' => (isset($cleaner->tables[$table])) ? true : false, )); } } break; case 2: // Remove the extra selected tables, and add the missing removed tables $error = array(); if ($apply_changes) { if (!function_exists('get_tables')) { include(PHPBB_ROOT_PATH . 'includes/functions_install.' . PHP_EXT); } $existing_tables = get_tables($db); $tables = array_unique(array_merge(array_keys($cleaner->tables), $existing_tables)); foreach ($tables as $table) { if (isset($selected[$table])) { if (isset($cleaner->tables[$table]) && !in_array($table, $existing_tables)) { $result = $umil->table_add($table, $cleaner->tables[$table]); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } } else if (!isset($cleaner->tables[$table]) && in_array($table, $existing_tables)) { $result = $umil->table_remove($table); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } } } } } if (!empty($error)) { $template->assign_var('ERROR_MESSAGE', implode('<br />', $error)); } else { $template->assign_var('SUCCESS_MESSAGE', $user->lang['DATABASE_TABLES_SUCCESS']); } // Time to start going through the database and listing any extra/missing fields $last_output_table = ''; foreach ($cleaner->tables as $table_name => $data) { // We shouldn't mess with profile fields here. Users probably will not know what this table does or what would happen if they remove fields added to it. if ($table_name == PROFILE_FIELDS_DATA_TABLE) { continue; } $existing_columns = $this->get_columns($table_name); if ($existing_columns === false) { // Table doesn't exist, don't handle here. continue; } $columns = array_unique(array_merge(array_keys($data['COLUMNS']), $existing_columns)); sort($columns); foreach ($columns as $column) { if ((!isset($data['COLUMNS'][$column]) && in_array($column, $existing_columns)) || (isset($data['COLUMNS'][$column]) && !in_array($column, $existing_columns))) { // Output the table block if it's not been done yet if ($last_output_table != $table_name) { $last_output_table = $table_name; $template->assign_block_vars('section', array( 'NAME' => $table_name, 'TITLE' => $user->lang['ROWS'], )); } $template->assign_block_vars('section.items', array( 'NAME' => $column, 'FIELD_NAME' => $table_name . '_' . $column, 'MISSING' => (!in_array($column, $existing_columns)) ? true : false, )); } } } break; case 3: // Update the tables according to what they selected last time $error = array(); if ($apply_changes) { foreach ($cleaner->tables as $table_name => $data) { if ($table_name == PROFILE_FIELDS_DATA_TABLE) { continue; } $existing_columns = $this->get_columns($table_name); if ($existing_columns === false) { // Table doesn't exist, don't handle here. continue; } $columns = array_unique(array_merge(array_keys($data['COLUMNS']), $existing_columns)); foreach ($columns as $column) { if (isset($selected[$table_name . '_' . $column])) { if (!isset($data['COLUMNS'][$column]) && in_array($column, $existing_columns)) { $result = $umil->table_column_remove($table_name, $column); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } } else if (isset($data['COLUMNS'][$column]) && !in_array($column, $existing_columns)) { // This can return an error under some circumstances, like when trying to add an auto-increment field (hope to hell nobody drops one of those) $result = $umil->table_column_add($table_name, $column, $data['COLUMNS'][$column]); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } // We can re-add *some* keys if (isset($data['KEYS'])) { if (in_array($column, $data['KEYS'])) { if ($data['KEYS'][$column][0] == 'INDEX' && $data['KEYS'][$column][1] == $column) { $result = $umil->table_index_add($table_name, $column, $column); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } } } } } } } } } if (!empty($error)) { $template->assign_var('ERROR_MESSAGE', implode('<br />', $error)); } else { $template->assign_var('SUCCESS_MESSAGE', $user->lang['DATABASE_COLUMNS_SUCCESS']); } // display extra config variables and let them check/uncheck the ones they want to add/remove $template->assign_block_vars('section', array( 'NAME' => $user->lang['CONFIG_SETTINGS'], 'TITLE' => $user->lang['ROWS'], )); $config_rows = $existing_config = array(); get_config_rows($cleaner, $config_rows, $existing_config); foreach ($config_rows as $name) { // Skip ones that are in the default install and are in the existing config if (isset($cleaner->config[$name]) && in_array($name, $existing_config)) { continue; } $template->assign_block_vars('section.items', array( 'NAME' => $name, 'FIELD_NAME' => $name, 'MISSING' => (!in_array($name, $existing_config)) ? true : false, )); } break; case 4 : // Add/remove the extra config variables they selected. if ($apply_changes) { $config_rows = $existing_config = array(); get_config_rows($cleaner, $config_rows, $existing_config); foreach ($config_rows as $name) { if (isset($cleaner->config[$name]) && in_array($name, $existing_config)) { continue; } if (isset($selected[$name])) { if (isset($cleaner->config[$name]) && !in_array($name, $existing_config)) { // Add it with the default settings we've got... set_config($name, $cleaner->config[$name]['config_value'], $cleaner->config[$name]['is_dynamic']); } else if (!isset($cleaner->config[$name]) && in_array($name, $existing_config)) { // Remove it $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $db->sql_escape($name) . "'"); } } } } $template->assign_var('SUCCESS_MESSAGE', $user->lang['CONFIG_UPDATE_SUCCESS']); // Display the extra permission fields and again let them select ones to add/remove $template->assign_block_vars('section', array( 'NAME' => $user->lang['PERMISSION_SETTINGS'], 'TITLE' => $user->lang['ROWS'], )); $permission_rows = $existing_permissions = array(); get_permission_rows($cleaner, $permission_rows, $existing_permissions); foreach ($permission_rows as $name) { // Skip ones that are in the default install and are in the existing permissions if (isset($cleaner->permissions[$name]) && in_array($name, $existing_permissions)) { continue; } $template->assign_block_vars('section.items', array( 'NAME' => $name, 'FIELD_NAME' => $name, 'MISSING' => (!in_array($name, $existing_permissions)) ? true : false, )); } break; case 5 : // Add/remove the permission fields they selected if ($apply_changes) { $permission_rows = $existing_permissions = array(); get_permission_rows($cleaner, $permission_rows, $existing_permissions); foreach ($permission_rows as $name) { // Skip ones that are in the default install and are in the existing permissions if (isset($cleaner->permissions[$name]) && in_array($name, $existing_permissions)) { continue; } if (isset($selected[$name])) { if (isset($cleaner->permissions[$name]) && !in_array($name, $existing_permissions)) { // Add it with the default settings we've got... $umil->permission_add($name, (($cleaner->permissions[$name]['is_global']) ? true : false)); } else if (!isset($cleaner->permissions[$name]) && in_array($name, $existing_permissions)) { // Remove it $umil->permission_remove($name, true); $umil->permission_remove($name, false); } } } } $template->assign_var('SUCCESS_MESSAGE', $user->lang['PERMISSION_UPDATE_SUCCESS']); // Display the system groups that are missing or aren't from a vanilla installation $template->assign_block_vars('section', array( 'NAME' => $user->lang['ACP_GROUPS_MANAGEMENT'], 'TITLE' => $user->lang['ROWS'], )); $group_rows = $existing_groups = array(); get_group_rows($cleaner, $group_rows, $existing_groups); foreach ($group_rows as $name) { // Skip ones that are in the default install and are in the existing permissions if (isset($cleaner->groups[$name]) && in_array($name, $existing_groups)) { continue; } $template->assign_block_vars('section.items', array( 'NAME' => $name, 'FIELD_NAME' => $name, 'MISSING' => (!in_array($name, $existing_groups)) ? true : false, )); } break; case 6: // Add/remove selected system groups if ($apply_changes) { $group_rows = $existing_groups = array(); get_group_rows($cleaner, $group_rows, $existing_groups); foreach ($group_rows as $name) { // Skip ones that are in the default install and are in the existing permissions if (isset($cleaner->groups[$name]) && in_array($name, $existing_groups)) { continue; } if (isset($selected[$name])) { if (isset($cleaner->groups[$name]) && !in_array($name, $existing_groups)) { // Add it with the default settings we've got... $group_id = false; group_create($group_id, $cleaner->groups[$name]['group_type'], $name, $cleaner->groups[$name]['group_desc'], array('group_colour' => $cleaner->groups[$name]['group_colour'], 'group_legend' => $cleaner->groups[$name]['group_legend'], 'group_avatar' => $cleaner->groups[$name]['group_avatar'], 'group_max_recipients' => $cleaner->groups[$name]['group_max_recipients'])); } else if (!isset($cleaner->groups[$name]) && in_array($name, $existing_groups)) { // Remove it $db->sql_query('SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $name . '\''); $group_id = $db->sql_fetchfield('group_id'); group_delete($group_id, $name); } } } } // Ask if they would like to reset the modules (handled in the template) $template->assign_vars(array( 'S_MODULE_OPTIONS' => true, 'S_NO_INSTRUCTIONS' => true, )); break; case 7 : // Reset the modules if they wanted to if (isset($_POST['yes']) && $apply_changes) { // Remove existing modules $db->sql_query('DELETE FROM ' . MODULES_TABLE); // Add the modules $db->sql_multi_insert(MODULES_TABLE, $cleaner->modules); $template->assign_var('SUCCESS_MESSAGE', $user->lang['RESET_MODULE_SUCCESS']); } // Ask if they would like to reset the bots (handled in the template) $template->assign_vars(array( 'S_BOT_OPTIONS' => true, 'S_NO_INSTRUCTIONS' => true, )); break; case 8 : // Reset the bots if they wanted to if (isset($_POST['yes']) && $apply_changes) { $sql = 'SELECT group_id, group_colour FROM ' . GROUPS_TABLE . " WHERE group_name = 'BOTS'"; $result = $db->sql_query($sql); $group_id = (int) $db->sql_fetchfield('group_id', false, $result); $group_colour = $db->sql_fetchfield('group_colour', 0, $result); $db->sql_freeresult($result); if (!$group_id) { // If we reach this point then something has gone very wrong $template->assign_var('ERROR_MESSAGE', $user->lang['NO_BOT_GROUP']); } else { if (!function_exists('user_add')) { include(PHPBB_ROOT_PATH . 'includes/functions_user.' . PHP_EXT); } // Remove existing bots $uids = array(); $sql = 'SELECT user_id FROM ' . BOTS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $uids[] = $row['user_id']; } $db->sql_freeresult($result); if (!empty($uids)) { $db->sql_query('DELETE FROM ' . USERS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', $uids)); $db->sql_query('DELETE FROM ' . BOTS_TABLE); } // Add the bots foreach ($this->bot_list as $bot_name => $bot_ary) { $user_row = array( 'user_type' => USER_IGNORE, 'group_id' => $group_id, 'username' => $bot_name, 'user_regdate' => time(), 'user_password' => '', 'user_colour' => $group_colour, 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => 1, 'user_timezone' => 0, 'user_dateformat' => $config['default_dateformat'], 'user_allow_massemail' => 0, ); $user_id = user_add($user_row); if ($user_id) { $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( 'bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, 'bot_agent' => (string) $bot_ary[0], 'bot_ip' => (string) $bot_ary[1], )); $result = $db->sql_query($sql); } } $template->assign_var('SUCCESS_MESSAGE', $user->lang['RESET_BOT_SUCCESS']); } } // Misc things will be done next $template->assign_vars(array( 'SUCCESS_MESSAGE' => $user->lang['FINAL_STEP'], 'S_NO_INSTRUCTIONS' => true, )); break; case 9 : if ($apply_changes) { set_config('board_disable', 0); $umil->cache_purge(); $umil->cache_purge('auth'); } // Finished? trigger_error('DATABASE_CLEANER_SUCCESS'); break; } page_header($user->lang['DATABASE_CLEANER'], false); $template->assign_vars(array( 'STEP' => $step, 'U_NEXT_STEP' => append_sid(STK_INDEX, 't=database_cleaner&step=' . ($step + 1)), )); $template->set_filenames(array( 'body' => 'tools/database_cleaner.html', )); page_footer(); }
function get_rows($table_id, $id = false) { global $dbh; global $cms_user; $results = array(); // Get table name info based on ID... forces to check if table exists $tables = get_tables(); $table = $tables[$table_id]; if ($table) { // If the user has header preferences for this table $results['header_fields'] = false; $results['sort_field'] = false; $sth = $dbh->prepare("SELECT * FROM `directus_preferences` WHERE `user` = :user AND `name` = :name "); $sth->bindParam(':user', $cms_user['id']); $sth->bindParam(':name', $table); $sth->execute(); while ($user_table_preferences = $sth->fetch()) { $results[$user_table_preferences['type']] = $user_table_preferences['value']; } // Set the table names $results['table_id'] = $table_id; $results['name'] = $table; $results['name_uc'] = uc_table($table); // Get and set the table info $table_info = get_rows_info($table); $results['info'] = $table_info['info']; $results['active'] = $table_info['active']; $results['sort'] = $table_info['sort']; $results['num'] = $table_info['num']; $results['fields'] = $table_info['fields']; // Get the rows if ($id != 'bypass') { $query_rows = "SELECT * FROM `{$table}` WHERE 1=1 "; if ($id !== false) { // Check to make sure this is JUST an ID $id = intval($id); // Limit results to just this ID if given $query_rows .= "AND `id` = '{$id}' LIMIT 1 "; $results['item_id'] = $id; } else { ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Add or Update user field sort preference // Clean variables $_GET['direction'] = $_GET['direction'] == 'DESC' ? 'DESC' : 'ASC'; $_GET['sort'] = $_GET['sort'] == 'sort' || in_array($_GET['sort'], $results['fields']) ? $_GET['sort'] : false; if ($_GET['sort'] && $_GET['direction']) { if ($results['sort_field']) { $query = "UPDATE `directus_preferences` SET `value` = :value WHERE `user` = :user AND `name` = :name AND `type` = 'sort_field' "; } else { $query = "INSERT INTO `directus_preferences` SET `value` = :value, `user` = :user, `name` = :name, `type` = 'sort_field' "; } $results['sort_field'] = $_GET['sort'] . ' ' . $_GET['direction']; $sth = $dbh->prepare($query); $sth->bindParam(':user', $cms_user['id']); $sth->bindParam(':name', $table); $sth->bindParam(':value', $results['sort_field']); $sth->execute(); } if ($results['sort_field']) { // Sort by user preferences $query_rows .= $table_info['sort'] ? "ORDER BY " . $results['sort_field'] . ", `sort` ASC " : "ORDER BY " . $results['sort_field'] . " "; } else { // Sort by SORT and ID if there is an sort field, or just ID if not $query_rows .= $table_info['sort'] ? "ORDER BY `sort` ASC, `id` ASC " : "ORDER BY `id` ASC "; } } $results['sql'] = $query_rows; $results['rows'] = array(); $sth = $dbh->query($query_rows); while ($row_rows = $sth->fetch()) { $results['rows'][$row_rows['id']] = $row_rows; } } return $results; } else { return false; } }
/** * Used to test whether we are able to connect to the database the user has specified * and identify any problems (eg there are already tables with the names we want to use * @param array $dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()} * necessary extensions should be loaded already */ function critical_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) { // Must be globalized here for when including the DB file global $phpbb_root_path, $phpEx; $dbms = $dbms_details['DRIVER']; if ($load_dbal) { // Include the DB layer include PHPBB_ROOT_PATH . 'includes/db/' . $dbms . '.' . PHP_EXT; } // Instantiate it and set return on error true $sql_db = 'dbal_' . $dbms; $db = new $sql_db(); $db->sql_return_on_error(true); // Check that we actually have a database name before going any further..... if ($dbms_details['DRIVER'] != 'sqlite' && $dbms_details['DRIVER'] != 'oracle' && $dbname === '') { $error[] = 'No database name specified.'; return false; } // Check the prefix length to ensure that index names are not too long and does not contain invalid characters switch ($dbms_details['DRIVER']) { case 'mysql': case 'mysqli': if (strspn($table_prefix, '-./\\') !== 0) { $error[] = 'The table prefix you have specified is invalid for your database.'; return false; } // no break; // no break; case 'postgres': $prefix_length = 36; break; case 'mssql': case 'mssql_odbc': $prefix_length = 90; break; case 'sqlite': $prefix_length = 200; break; case 'firebird': case 'oracle': $prefix_length = 6; break; } if (strlen($table_prefix) > $prefix_length) { $error[] = 'The table prefix you have specified is invalid for your database.'; return false; } // Try and connect ... if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true))) { $db_error = $db->sql_error(); $error[] = 'Could not connect to the database, see error message below.' . '<br />' . ($db_error['message'] ? $db_error['message'] : 'No error message given.'); } else { // Make sure that the user has selected a sensible DBAL for the DBMS actually installed switch ($dbms_details['DRIVER']) { case 'mysqli': if (version_compare(mysqli_get_server_info($db->db_connect_id), '4.1.3', '<')) { $error[] = 'The version of MySQL installed on this machine is incompatible with the “MySQL with MySQLi Extension” option you have selected. Please try the “MySQL” option instead.'; } break; case 'sqlite': if (version_compare(sqlite_libversion(), '2.8.2', '<')) { $error[] = 'The version of the SQLite extension you have installed is too old, it must be upgraded to at least 2.8.2.'; } break; case 'firebird': // check the version of FB, use some hackery if we can't get access to the server info if ($db->service_handle !== false && function_exists('ibase_server_info')) { $val = @ibase_server_info($db->service_handle, IBASE_SVC_SERVER_VERSION); preg_match('#V([\\d.]+)#', $val, $match); if ($match[1] < 2) { $error[] = 'The version of Firebird installed on this machine is older than 2.0, please upgrade to a newer version.'; } $db_info = @ibase_db_info($db->service_handle, $dbname, IBASE_STS_HDR_PAGES); preg_match('/^\\s*Page size\\s*(\\d+)/m', $db_info, $regs); $page_size = intval($regs[1]); if ($page_size < 8192) { $error[] = 'The database you selected for Firebird has a page size less than 8192, it must be at least 8192.'; } } else { $sql = "SELECT *\n\t\t\t\t\t\t\tFROM RDB{$FUNCTIONS}\n\t\t\t\t\t\t\tWHERE RDB{$SYSTEM_FLAG} IS NULL\n\t\t\t\t\t\t\t\tAND RDB{$FUNCTION_NAME} = 'CHAR_LENGTH'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // if its a UDF, its too old if ($row) { $error[] = 'The version of Firebird installed on this machine is older than 2.0, please upgrade to a newer version.'; } else { $sql = "SELECT FIRST 0 char_length('')\n\t\t\t\t\t\t\t\tFROM RDB\$DATABASE"; $result = $db->sql_query($sql); if (!$result) { $error[] = 'The version of Firebird installed on this machine is older than 2.0, please upgrade to a newer version.'; } $db->sql_freeresult($result); } // Setup the stuff for our random table $char_array = array_merge(range('A', 'Z'), range('0', '9')); $char_len = mt_rand(7, 9); $char_array_len = sizeof($char_array) - 1; $final = ''; for ($i = 0; $i < $char_len; $i++) { $final .= $char_array[mt_rand(0, $char_array_len)]; } // Create some random table $sql = 'CREATE TABLE ' . $final . " (\n\t\t\t\t\t\t\tFIELD1 VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE,\n\t\t\t\t\t\t\tFIELD2 INTEGER DEFAULT 0 NOT NULL);"; $db->sql_query($sql); // Create an index that should fail if the page size is less than 8192 $sql = 'CREATE INDEX ' . $final . ' ON ' . $final . '(FIELD1, FIELD2);'; $db->sql_query($sql); if (ibase_errmsg() !== false) { $error[] = 'The database you selected for Firebird has a page size less than 8192, it must be at least 8192.'; } else { // Kill the old table $db->sql_query('DROP TABLE ' . $final . ';'); } unset($final); } break; case 'oracle': if ($unicode_check) { $sql = "SELECT *\n\t\t\t\t\t\t\tFROM NLS_DATABASE_PARAMETERS\n\t\t\t\t\t\t\tWHERE PARAMETER = 'NLS_RDBMS_VERSION'\n\t\t\t\t\t\t\t\tOR PARAMETER = 'NLS_CHARACTERSET'"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $stats[$row['parameter']] = $row['value']; } $db->sql_freeresult($result); if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8') { $error[] = 'The version of Oracle installed on this machine requires you to set the <var>NLS_CHARACTERSET</var> parameter to <var>UTF8</var>. Either upgrade your installation to 9.2+ or change the parameter.'; } } break; case 'postgres': if ($unicode_check) { $sql = "SHOW server_encoding;"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8') { $error[] = 'The database you have selected was not created in <var>UNICODE</var> or <var>UTF8</var> encoding. Try installing with a database in <var>UNICODE</var> or <var>UTF8</var> encoding.'; } } break; } $tables = get_tables($db); if (!in_array($table_prefix . 'acl_options', $tables) || !in_array($table_prefix . 'config', $tables) || !in_array($table_prefix . 'forums', $tables)) { $error[] = 'phpBB3 tables could not be found on this database with this table prefix.'; } } if ($error_connect && empty($error)) { return true; } return false; }
$page['errors'] = array(); $step = 3; updates::upgrade_to('2.3.4', $step, false); if (!empty($page['errors'])) { echo '<ul>'; foreach ($page['errors'] as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } exit; } // +-----------------------------------------------------------------------+ // | upgrade choice | // +-----------------------------------------------------------------------+ $tables = get_tables(); $columns_of = get_columns_of($tables); // find the current release if (!in_array('param', $columns_of[PREFIX_TABLE . 'config'])) { // we're in branch 1.3, important upgrade, isn't it? if (in_array(PREFIX_TABLE . 'user_category', $tables)) { $current_release = '1.3.1'; } else { $current_release = '1.3.0'; } } else { if (!in_array(PREFIX_TABLE . 'user_cache', $tables)) { $current_release = '1.4.0'; } else { if (!in_array(PREFIX_TABLE . 'tags', $tables)) { $current_release = '1.5.0';
/** * Used to test whether we are able to connect to the database the user has specified * and identify any problems (eg there are already tables with the names we want to use * @param array $dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()} * necessary extensions should be loaded already */ 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) { global $phpbb_root_path, $phpEx, $config, $lang; $dbms = $dbms_details['DRIVER']; // Instantiate it and set return on error true $db = new $dbms(); $db->sql_return_on_error(true); // Check that we actually have a database name before going any further..... if ($dbms_details['DRIVER'] != 'phpbb\\db\\driver\\sqlite' && $dbms_details['DRIVER'] != 'phpbb\\db\\driver\\sqlite3' && $dbms_details['DRIVER'] != 'phpbb\\db\\driver\\oracle' && $dbname === '') { $error[] = $lang['INST_ERR_DB_NO_NAME']; return false; } // Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea if (($dbms_details['DRIVER'] == 'phpbb\\db\\driver\\sqlite' || $dbms_details['DRIVER'] == 'phpbb\\db\\driver\\sqlite3') && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0) { $error[] = $lang['INST_ERR_DB_FORUM_PATH']; return false; } // Check the prefix length to ensure that index names are not too long and does not contain invalid characters switch ($dbms_details['DRIVER']) { case 'phpbb\\db\\driver\\mysql': case 'phpbb\\db\\driver\\mysqli': if (strspn($table_prefix, '-./\\') !== 0) { $error[] = $lang['INST_ERR_PREFIX_INVALID']; return false; } // no break; // no break; case 'phpbb\\db\\driver\\postgres': $prefix_length = 36; break; case 'phpbb\\db\\driver\\mssql': case 'phpbb\\db\\driver\\mssql_odbc': case 'phpbb\\db\\driver\\mssqlnative': $prefix_length = 90; break; case 'phpbb\\db\\driver\\sqlite': case 'phpbb\\db\\driver\\sqlite3': $prefix_length = 200; break; case 'phpbb\\db\\driver\\oracle': $prefix_length = 6; break; } if (strlen($table_prefix) > $prefix_length) { $error[] = sprintf($lang['INST_ERR_PREFIX_TOO_LONG'], $prefix_length); return false; } // Try and connect ... if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true))) { $db_error = $db->sql_error(); $error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . ($db_error['message'] ? utf8_convert_message($db_error['message']) : $lang['INST_ERR_DB_NO_ERROR']); } else { // Likely matches for an existing phpBB installation if (!$prefix_may_exist) { $temp_prefix = strtolower($table_prefix); $table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users'); $tables = get_tables($db); $tables = array_map('strtolower', $tables); $table_intersect = array_intersect($tables, $table_ary); if (sizeof($table_intersect)) { $error[] = $lang['INST_ERR_PREFIX']; } } // Make sure that the user has selected a sensible DBAL for the DBMS actually installed switch ($dbms_details['DRIVER']) { case 'phpbb\\db\\driver\\mysqli': if (version_compare(mysqli_get_server_info($db->get_db_connect_id()), '4.1.3', '<')) { $error[] = $lang['INST_ERR_DB_NO_MYSQLI']; } break; case 'phpbb\\db\\driver\\sqlite': if (version_compare(sqlite_libversion(), '2.8.2', '<')) { $error[] = $lang['INST_ERR_DB_NO_SQLITE']; } break; case 'phpbb\\db\\driver\\sqlite3': $version = \SQLite3::version(); if (version_compare($version['versionString'], '3.6.15', '<')) { $error[] = $lang['INST_ERR_DB_NO_SQLITE3']; } break; case 'phpbb\\db\\driver\\oracle': if ($unicode_check) { $sql = "SELECT *\n\t\t\t\t\t\tFROM NLS_DATABASE_PARAMETERS\n\t\t\t\t\t\tWHERE PARAMETER = 'NLS_RDBMS_VERSION'\n\t\t\t\t\t\t\tOR PARAMETER = 'NLS_CHARACTERSET'"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $stats[$row['parameter']] = $row['value']; } $db->sql_freeresult($result); if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8') { $error[] = $lang['INST_ERR_DB_NO_ORACLE']; } } break; case 'phpbb\\db\\driver\\postgres': if ($unicode_check) { $sql = "SHOW server_encoding;"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8') { $error[] = $lang['INST_ERR_DB_NO_POSTGRES']; } } break; } } if ($error_connect && (!isset($error) || !sizeof($error))) { return true; } return false; }
/** */ function get_convert_settings($sub) { global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache; require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); $db = new $sql_db(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); unset($dbpasswd); $this->page_title = $lang['STAGE_SETTINGS']; // We need to fill the config to let internal functions correctly work $sql = 'SELECT * FROM ' . CONFIG_TABLE; $result = $db->sql_query($sql); $config = array(); while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); $convertor_tag = request_var('tag', ''); if (empty($convertor_tag)) { $this->p_master->error($lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__); } $get_info = true; // check security implications of direct inclusion $convertor_tag = basename($convertor_tag); if (!file_exists('./convertors/convert_' . $convertor_tag . '.' . $phpEx)) { $this->p_master->error($lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__); } include('./convertors/convert_' . $convertor_tag . '.' . $phpEx); // The test_file is a file that should be present in the location of the old board. if (!isset($test_file)) { $this->p_master->error($lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__); } $submit = (isset($_POST['submit'])) ? true : false; $src_dbms = request_var('src_dbms', $convertor_data['dbms']); $src_dbhost = request_var('src_dbhost', $convertor_data['dbhost']); $src_dbport = request_var('src_dbport', $convertor_data['dbport']); $src_dbuser = request_var('src_dbuser', $convertor_data['dbuser']); $src_dbpasswd = request_var('src_dbpasswd', $convertor_data['dbpasswd']); $src_dbname = request_var('src_dbname', $convertor_data['dbname']); $src_table_prefix = request_var('src_table_prefix', $convertor_data['table_prefix']); $forum_path = request_var('forum_path', $convertor_data['forum_path']); $refresh = request_var('refresh', 1); // Default URL of the old board // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it? // -> We should convert old urls to the new relative urls format // $src_url = request_var('src_url', 'Not in use at the moment'); // strip trailing slash from old forum path $forum_path = (strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/') ? substr($forum_path, 0, -1) : $forum_path; $error = array(); if ($submit) { if (!@file_exists('./../' . $forum_path . '/' . $test_file)) { $error[] = sprintf($lang['COULD_NOT_FIND_PATH'], $forum_path); } $connect_test = false; $available_dbms = get_available_dbms(false, true, true); if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) { $error['db'][] = $lang['INST_ERR_NO_DB']; $connect_test = false; } else { $connect_test = connect_check_db(true, $error, $available_dbms[$src_dbms], $src_table_prefix, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, true, ($src_dbms == $dbms) ? false : true, false); } // The forum prefix of the old and the new forum can only be the same if two different databases are used. if ($src_table_prefix == $table_prefix && $src_dbms == $dbms && $src_dbhost == $dbhost && $src_dbport == $dbport && $src_dbname == $dbname) { $error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix); } // Check table prefix if (!sizeof($error)) { // initiate database connection to old db if old and new db differ global $src_db, $same_db; $src_db = $same_db = false; if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) { $sql_db = 'dbal_' . $src_dbms; $src_db = new $sql_db(); $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true); $same_db = false; } else { $src_db = $db; $same_db = true; } $src_db->sql_return_on_error(true); $db->sql_return_on_error(true); // Try to select one row from the first table to see if the prefix is OK $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1); if (!$result) { $prefixes = array(); $tables_existing = get_tables($src_db); $tables_existing = array_map('strtolower', $tables_existing); foreach ($tables_existing as $table_name) { compare_table($tables, $table_name, $prefixes); } unset($tables_existing); foreach ($prefixes as $prefix => $count) { if ($count >= sizeof($tables)) { $possible_prefix = $prefix; break; } } $msg = ''; if (!empty($convertor_data['table_prefix'])) { $msg .= sprintf($lang['DEFAULT_PREFIX_IS'], $convertor_data['forum_name'], $convertor_data['table_prefix']); } if (!empty($possible_prefix)) { $msg .= '<br />'; $msg .= ($possible_prefix == '*') ? $lang['BLANK_PREFIX_FOUND'] : sprintf($lang['PREFIX_FOUND'], $possible_prefix); $src_table_prefix = ($possible_prefix == '*') ? '' : $possible_prefix; } $error[] = $msg; } $src_db->sql_freeresult($result); $src_db->sql_return_on_error(false); } if (!sizeof($error)) { // Save convertor Status set_config('convert_progress', serialize(array( 'step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor_tag, )), true); set_config('convert_db_server', serialize(array( 'dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname, )), true); set_config('convert_db_user', serialize(array( 'dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd, )), true); // Save options set_config('convert_options', serialize(array('forum_path' => './../' . $forum_path, 'refresh' => $refresh)), true); $template->assign_block_vars('checks', array( 'TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => $lang['CONVERT_SETTINGS_VERIFIED'], )); $template->assign_vars(array( 'L_SUBMIT' => $lang['BEGIN_CONVERT'], // 'S_HIDDEN' => $s_hidden_fields, 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag=$convertor_tag&language=$language", )); return; } else { $template->assign_block_vars('checks', array( 'TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => '<b style="color:red">' . implode('<br />', $error) . '</b>', )); } } // end submit foreach ($this->convert_options as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $template->assign_block_vars('options', array( 'S_LEGEND' => true, 'LEGEND' => $lang[$vars]) ); continue; } $options = isset($vars['options']) ? $vars['options'] : ''; $template->assign_block_vars('options', array( 'KEY' => $config_key, 'TITLE' => $lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'S_LEGEND' => false, 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '', 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $$config_key, $options), ) ); } $template->assign_vars(array( 'TITLE' => $lang['STAGE_SETTINGS'], 'BODY' => $lang['CONV_OPTIONS_BODY'], 'L_SUBMIT' => $lang['BEGIN_CONVERT'], 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=settings&tag=$convertor_tag&language=$language", )); }
function main($id, $mode) { global $db, $user, $auth, $template, $table_prefix; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/database'); $this->tpl_name = 'acp_database'; $this->page_title = 'ACP_DATABASE'; $action = request_var('action', ''); $submit = (isset($_POST['submit'])) ? true : false; $template->assign_vars(array( 'MODE' => $mode )); switch ($mode) { case 'backup': $this->page_title = 'ACP_BACKUP'; switch ($action) { case 'download': $type = request_var('type', ''); $table = request_var('table', array('')); $format = request_var('method', ''); $where = request_var('where', ''); if (!sizeof($table)) { trigger_error($user->lang['TABLE_SELECT_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } $store = $download = $structure = $schema_data = false; if ($where == 'store_and_download' || $where == 'store') { $store = true; } if ($where == 'store_and_download' || $where == 'download') { $download = true; } if ($type == 'full' || $type == 'structure') { $structure = true; } if ($type == 'full' || $type == 'data') { $schema_data = true; } @set_time_limit(1200); $time = time(); $filename = 'backup_' . $time . '_' . unique_id(); switch ($db->sql_layer) { case 'mysqli': case 'mysql4': case 'mysql': $extractor = new mysql_extractor($download, $store, $format, $filename, $time); break; case 'sqlite': $extractor = new sqlite_extractor($download, $store, $format, $filename, $time); break; case 'postgres': $extractor = new postgres_extractor($download, $store, $format, $filename, $time); break; case 'oracle': $extractor = new oracle_extractor($download, $store, $format, $filename, $time); break; case 'mssql': case 'mssql_odbc': $extractor = new mssql_extractor($download, $store, $format, $filename, $time); break; case 'firebird': $extractor = new firebird_extractor($download, $store, $format, $filename, $time); break; } $extractor->write_start($table_prefix); foreach ($table as $table_name) { // Get the table structure if ($structure) { $extractor->write_table($table_name); } else { // We might wanna empty out all that junk :D switch ($db->sql_layer) { case 'sqlite': case 'firebird': $extractor->flush('DELETE FROM ' . $table_name . ";\n"); break; case 'mssql': case 'mssql_odbc': $extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n"); break; case 'oracle': $extractor->flush('TRUNCATE TABLE ' . $table_name . "\\\n"); break; default: $extractor->flush('TRUNCATE TABLE ' . $table_name . ";\n"); break; } } // Data if ($schema_data) { $extractor->write_data($table_name); } } $extractor->write_end(); if ($download == true) { exit; } add_log('admin', 'LOG_DB_BACKUP'); trigger_error($user->lang['BACKUP_SUCCESS'] . adm_back_link($this->u_action)); break; default: include($phpbb_root_path . 'includes/functions_install.' . $phpEx); $tables = get_tables($db); foreach ($tables as $table_name) { if (strlen($table_prefix) === 0 || stripos($table_name, $table_prefix) === 0) { $template->assign_block_vars('tables', array( 'TABLE' => $table_name )); } } unset($tables); $template->assign_vars(array( 'U_ACTION' => $this->u_action . '&action=download' )); $available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $template->assign_block_vars('methods', array( 'TYPE' => $type )); } $template->assign_block_vars('methods', array( 'TYPE' => 'text' )); break; } break; case 'restore': $this->page_title = 'ACP_RESTORE'; switch ($action) { case 'submit': $delete = request_var('delete', ''); $file = request_var('file', ''); if (!preg_match('#^backup_\d{10,}_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches)) { trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $file_name = $phpbb_root_path . 'store/' . $matches[0]; if (!file_exists($file_name) || !is_readable($file_name)) { trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($delete) { if (confirm_box(true)) { unlink($file_name); add_log('admin', 'LOG_DB_DELETE'); trigger_error($user->lang['BACKUP_DELETE'] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['DELETE_SELECTED_BACKUP'], build_hidden_fields(array('delete' => $delete, 'file' => $file))); } } else { $download = request_var('download', ''); if ($download) { $name = $matches[0]; switch ($matches[1]) { case 'sql': $mimetype = 'text/x-sql'; break; case 'sql.bz2': $mimetype = 'application/x-bzip2'; break; case 'sql.gz': $mimetype = 'application/x-gzip'; break; } header('Pragma: no-cache'); header("Content-Type: $mimetype; name=\"$name\""); header("Content-disposition: attachment; filename=$name"); @set_time_limit(0); $fp = @fopen($file_name, 'rb'); if ($fp !== false) { while (!feof($fp)) { echo fread($fp, 8192); } fclose($fp); } flush(); exit; } switch ($matches[1]) { case 'sql': $fp = fopen($file_name, 'rb'); $read = 'fread'; $seek = 'fseek'; $eof = 'feof'; $close = 'fclose'; $fgetd = 'fgetd'; break; case 'sql.bz2': $fp = bzopen($file_name, 'r'); $read = 'bzread'; $seek = ''; $eof = 'feof'; $close = 'bzclose'; $fgetd = 'fgetd_seekless'; break; case 'sql.gz': $fp = gzopen($file_name, 'rb'); $read = 'gzread'; $seek = 'gzseek'; $eof = 'gzeof'; $close = 'gzclose'; $fgetd = 'fgetd'; break; } switch ($db->sql_layer) { case 'mysql': case 'mysql4': case 'mysqli': case 'sqlite': while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false) { $db->sql_query($sql); } break; case 'firebird': $delim = ";\n"; while (($sql = $fgetd($fp, $delim, $read, $seek, $eof)) !== false) { $query = trim($sql); if (substr($query, 0, 8) === 'SET TERM') { $delim = $query[9] . "\n"; continue; } $db->sql_query($query); } break; case 'postgres': while (($sql = $fgetd($fp, $delim, $read, $seek, $eof)) !== false) { $query = trim($sql); $db->sql_query($query); if (substr($query, 0, 4) == 'COPY') { while (($sub = $fgetd($fp, "\n", $read, $seek, $eof)) !== '\.') { if ($sub === false) { trigger_error($user->lang['RESTORE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING); } pg_put_line($db->db_connect_id, $sub . "\n"); } pg_put_line($db->db_connect_id, "\\.\n"); pg_end_copy($db->db_connect_id); } } break; case 'oracle': while (($sql = $fgetd($fp, "/\n", $read, $seek, $eof)) !== false) { $db->sql_query($sql); } break; case 'mssql': case 'mssql_odbc': while (($sql = $fgetd($fp, "GO\n", $read, $seek, $eof)) !== false) { $db->sql_query($sql); } break; } $close($fp); add_log('admin', 'LOG_DB_RESTORE'); trigger_error($user->lang['RESTORE_SUCCESS'] . adm_back_link($this->u_action)); break; } default: $methods = array('sql'); $available_methods = array('sql.gz' => 'zlib', 'sql.bz2' => 'bz2'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $methods[] = $type; } $dir = $phpbb_root_path . 'store/'; $dh = @opendir($dir); if ($dh) { while (($file = readdir($dh)) !== false) { if (preg_match('#^backup_(\d{10,})_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches)) { $supported = in_array($matches[2], $methods); if ($supported == 'true') { $template->assign_block_vars('files', array( 'FILE' => $file, 'NAME' => gmdate("d-m-Y H:i:s", $matches[1]), 'SUPPORTED' => $supported )); } } } closedir($dh); } $template->assign_vars(array( 'U_ACTION' => $this->u_action . '&action=submit' )); break; } break; } }
function check_tables($link) { global $dbtables, $page, $webimroot; $curr_tables = get_tables($link); if ($curr_tables !== false) { $tocreate = array_diff(array_keys($dbtables), $curr_tables); if (count($tocreate) == 0) { $page['done'][] = getlocal("install.3.tables_exist"); return true; } else { $page['nextstep'] = getlocal("install.3.create"); $page['nextstepurl'] = "{$webimroot}/install/dbperform.php?act=ct"; } } return false; }
function show_tables() { $rst = get_tables(); $first_row = 1; ?> <table border="1"> <?php while ($row = sqlsrv_fetch_array($rst)) { if ($first_row == 1) { ?> <tr><th>Table Name</th><th>Short Description</th><th>In COE</th></tr> <?php $first_row = 0; } ?> <tr><td> <a href="?action=table_detail&table_name=<?php echo $row['Table_Name']; ?> "><?php echo $row['Table_Name']; ?> </td> <td><?php echo $row['Table_Short_Desc']; ?> </td> <td><?php echo $row['InCollegeOfEducationCopyOfSISData']; ?> </td></tr> <?php } ?> </table> <?php }