Пример #1
0
/**
 * This function creates the database tables.
 *
 * @param string $hostname
 * @param string $db_name
 * @param string $username
 * @param string $password
 * @return array returns an array with two indexes: [0] true/false, depending on whether the
 *               operation was a success. [1] error message / empty string if success.
 */
function ft_install_create_database($hostname, $db_name, $username, $password, $table_prefix)
{
    global $g_sql, $g_current_version, $g_release_type, $g_release_date, $g_db_table_charset;
    // connect to the database
    $link = @mysql_connect($hostname, $username, $password);
    @mysql_select_db($db_name);
    // suppress strict mode
    @mysql_query("SET SQL_MODE=''", $link);
    // check for the existence of Form Tools tables. It would be sad to accidentally delete/overwrite someone's
    // older installation!
    $errors = array();
    foreach ($g_sql as $query) {
        $query = preg_replace("/%PREFIX%/", $table_prefix, $query);
        $query = preg_replace("/%FORMTOOLSVERSION%/", $g_current_version, $query);
        $query = preg_replace("/%FORMTOOLSRELEASEDATE%/", $g_release_date, $query);
        $query = preg_replace("/%FORMTOOLSRELEASETYPE%/", $g_release_type, $query);
        $query = preg_replace("/%CHARSET%/", $g_db_table_charset, $query);
        // execute the queries. If any error occurs, break out of the installation loop, delete any and
        // all tables that have been created
        $result = mysql_query($query) or $errors[] = $query . " - <b>" . mysql_error() . "</b>";
        // problem! delete any tables we just added
        if (!$result) {
            ft_install_delete_tables($hostname, $db_name, $username, $password, $table_prefix);
            break;
        }
    }
    $success = true;
    $message = "";
    if (!empty($errors)) {
        $success = false;
        array_walk($errors, create_function('&$el', '$el = "&bull;&nbsp; " . $el;'));
        $message = join("<br />", $errors);
    }
    @mysql_close($link);
    // if there was an error, return the error message
    return array($success, $message);
}
Пример #2
0
$password = ft_load_field("g_db_password", "g_db_password", "", "ft_install");
$g_table_prefix = ft_load_field("g_table_prefix", "g_table_prefix", "ft_", "ft_install");
$step_complete = false;
$error = "";
$tables_already_exist = false;
$existing_tables = array();
if (isset($_POST["track_license_keys"])) {
    $module_folders = $_POST["module_folders"];
    $data = array();
    foreach ($module_folders as $module_folder) {
        $data[$module_folder] = array("k" => $_POST["{$module_folder}_k"], "ek" => $_POST["{$module_folder}_ek"]);
    }
    $_SESSION["ft_install"]["premium_module_keys"] = $data;
}
if (isset($_POST["overwrite_tables"])) {
    ft_install_delete_tables($hostname, $db_name, $username, $password, $g_table_prefix);
    $_POST["create_database"] = 1;
}
if (isset($_POST["create_database"])) {
    // confirm the database settings are correctly entered. If they're not, the error messages are
    // returned by this function, and the page is reloaded to display them
    list($success, $error) = ft_install_check_db_settings($hostname, $db_name, $username, $password);
    // all checks out! Now try to create the database tables
    if ($success) {
        $existing_tables = ft_check_no_existing_tables($hostname, $db_name, $username, $password, $g_table_prefix);
        if (empty($existing_tables)) {
            list($success, $error) = ft_install_create_database($hostname, $db_name, $username, $password, $g_table_prefix);
            if ($success) {
                header("location: step4.php");
                exit;
            }