Example #1
0
function DBQuery($sql)
{
    global $DatabaseType;
    $connection = db_start();
    switch ($DatabaseType) {
        case 'oracle':
            $result = @ociparse($connection, $sql);
            // TRANSLATION: do NOT translate these since error messages need to stay in English for technical support
            if ($result === false) {
                $errors = OCIError($connection);
                db_show_error($sql, "DB Parse Failed.", $errors['message']);
            }
            if (!@OciExecute($result)) {
                $errors = OCIError($result);
                db_show_error($sql, "DB Execute Failed.", $errors['message']);
            }
            OciCommit($connection);
            OciLogoff($connection);
            break;
        case 'postgres':
            // TRANSLATION: do NOT translate these since error messages need to stay in English for technical support
            $sql = preg_replace("/([,\\(=])[\r\n\t ]*''/", '\\1NULL', $sql);
            $result = @pg_exec($connection, $sql);
            if ($result === false) {
                $errstring = pg_last_error($connection);
                db_show_error($sql, "DB Execute Failed.", $errstring);
            }
            break;
        case 'mysql':
            // TRANSLATION: do NOT translate these since error messages need to stay in English for technical support
            mysql_query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE");
            mysql_query("SET SESSION SQL_MODE='ANSI'");
            $sql = preg_replace("/([,\\(=])[\r\n\t ]*''/", '\\1NULL', $sql);
            $result = mysql_query($sql);
            if ($result === false) {
                $errstring = mysql_error();
                db_show_error($sql, "DB Execute Failed.", $errstring);
            }
            break;
    }
    return $result;
}
Example #2
0
function DBQuery($sql)
{
    global $DatabaseType, $_CENTRE;
    $connection = db_start();
    switch ($DatabaseType) {
        case 'oracle':
            $result = @ociparse($connection, $sql);
            if ($result === false) {
                $errors = OCIError($connection);
                db_show_error($sql, "DB Parse Failed.", $errors['message']);
            }
            if (!@OciExecute($result)) {
                $errors = OCIError($result);
                db_show_error($sql, "DB Execute Failed.", $errors['message']);
            }
            OciCommit($connection);
            OciLogoff($connection);
            break;
        case 'postgres':
            $sql = ereg_replace("([,\\(=])[\r\n\t ]*''", '\\1NULL', $sql);
            $result = @pg_exec($connection, $sql);
            if ($result === false) {
                echo $sql;
                $errstring = pg_last_error($connection);
                db_show_error($sql, "DB Execute Failed.", $errstring);
            }
            break;
        case 'mysql':
            $sql = ereg_replace("([,\\(=])[\r\n\t ]*''", '\\1NULL', $sql);
            if (preg_match_all("/'(\\d\\d-[A-Za-z]{3}-\\d{2,4})'/", $sql, $matches)) {
                foreach ($matches[1] as $match) {
                    $dt = date('Y-m-d', strtotime($match));
                    $sql = preg_replace("/'{$match}'/", "'{$dt}'", $sql);
                }
            }
            if (substr($sql, 0, 6) == "BEGIN;") {
                $array = explode(";", $sql);
                foreach ($array as $value) {
                    if ($value != "") {
                        $result = mysql_query($value);
                        if (!$result) {
                            mysql_query("ROLLBACK");
                            die(db_show_error($sql, "DB Execute Failed.", mysql_error()));
                        }
                    }
                }
            } else {
                $result = mysql_query($sql) or die(db_show_error($sql, "DB Execute Failed.", mysql_error()));
            }
            break;
    }
    return $result;
}