Example #1
0
function do_cryptdb_sql($cdbh, $q)
{
    global $last_sth, $last_sql, $reccount, $out_message, $SQLq, $SHOW_T;
    $SQLq = $q;
    if (!do_multi_sql($q)) {
        $out_message = "Error: " . $cdbh->error;
    } else {
        if ($last_sth && $last_sql) {
            $SQLq = $last_sql;
            if (preg_match("/^select|show|explain|desc/i", $last_sql)) {
                if ($q != $last_sql) {
                    $out_message = "Results of the last select displayed:";
                }
                display_select($last_sth, $last_sql);
            } else {
                $reccount = mysql_affected_rows($cryptdbh);
                $out_message = "Done.";
                if (preg_match("/^insert|replace/i", $last_sql)) {
                    $out_message .= " Last inserted id=" . get_identity();
                }
                if (preg_match("/^drop|truncate/i", $last_sql)) {
                    do_sql($SHOW_T);
                }
            }
        }
    }
}
Example #2
0
function do_import()
{
    global $err_msg, $out_message, $dbh;
    if ($_FILES['file1'] && $_FILES['file1']['name']) {
        $filename = $_FILES['file1']['tmp_name'];
        if (!do_multi_sql('', $filename)) {
            $err_msg = "Error: " . mysql_error($dbh);
        } else {
            $out_message = 'Import done successfully';
            do_sql('show tables');
            return;
        }
    } else {
        $err_msg = "Error: Please select file first";
    }
    print_import();
    exit;
}
Example #3
0
function do_import()
{
    global $err_msg, $out_message, $dbh, $SHOW_T;
    $err_msg = '';
    $F = $_FILES['file1'];
    if ($F && $F['name']) {
        $filename = $F['tmp_name'];
        $pi = pathinfo($F['name']);
        if ($pi['extension'] != 'sql') {
            //if not sql - assume .gz
            $tmpf = tmp_name();
            if (($gz = gzopen($filename, 'rb')) && ($tf = fopen($tmpf, 'wb'))) {
                while (!gzeof($gz)) {
                    if (fwrite($tf, gzread($gz, 8192), 8192) === FALSE) {
                        $err_msg = 'Error during gz file extraction to tmp file';
                        break;
                    }
                }
                //extract to tmp file
                gzclose($gz);
                fclose($tf);
                $filename = $tmpf;
            } else {
                $err_msg = 'Error opening gz file';
            }
        }
        if (!$err_msg) {
            if (!do_multi_sql('', $filename)) {
                $err_msg = 'Import Error: ' . mysql_error($dbh);
            } else {
                $out_message = 'Import done successfully';
                do_sql($SHOW_T);
                return;
            }
        }
    } else {
        $err_msg = "Error: Please select file first";
    }
    print_import();
    exit;
}
Example #4
0
                foreach (explode(' ', MODULES) as $mod) {
                    $files = array_merge($files, glob(DIR_FS_APP . DS . 'modules' . DS . $mod . DS . 'config' . DS . 'sql' . DS . '*.sql'));
                }
            }
        }
    }
}
if (empty($files)) {
    echo "No files found.\n";
    exit(1);
}
$db =& Registry::get('pronto:db:main');
foreach ($files as $f) {
    unset($GLOBALS['insql_done'], $GLOBALS['LFILE']);
    echo "Loading {$f}...\n";
    if (!do_multi_sql('', $f)) {
        echo "Error: An error occurred while trying to run this SQL chunk.\n";
    }
}
function do_sql($sql)
{
    global $db;
    $sql = trim($sql);
    if (empty($sql)) {
        return true;
    }
    return !!$db->execute($sql);
}
/**
 * The following functions were hijacked from PHPMiniAdmin,
 * found here: http://phpminiadmin.sourceforge.net