Example #1
0
function sti_firebird_get_data($connection_string, $data_source_name, $query)
{
    $info = sti_firebird_parse_connection_string($connection_string);
    $link = ibase_connect($info["host"] . ":" . $info["database"], $info["user_id"], $info["password"]) or die("ServerError:Could not connect to host '" . $info["host"] . "', database '" . $info["database"] . "'");
    $query = sti_parse_query_parameters($query);
    $result = ibase_query($link, $query) or die("ServerError:Data not found");
    $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>";
    $count = ibase_num_fields($result);
    for ($fid = 0; $fid < $count; $fid++) {
        $field_info = ibase_field_info($result, $fid);
        $columns[$fid] = $field_info['alias'];
    }
    while ($row = ibase_fetch_assoc($result)) {
        $xml_output .= "<{$data_source_name}>";
        foreach ($columns as $column) {
            $value = $row[$column];
            $value = str_replace("&", "&amp;", $value);
            $value = str_replace("<", "&lt;", $value);
            $value = str_replace(">", "&gt;", $value);
            $xml_output .= "<{$column}>{$value}</{$column}>";
        }
        $xml_output .= "</{$data_source_name}>";
    }
    $xml_output .= "</Database>";
    ibase_free_result($result);
    ibase_close($link);
    return $xml_output;
}
Example #2
0
function sti_mysql_get_data($connection_string, $data_source_name, $query)
{
    $info = sti_mysql_parse_connection_string($connection_string);
    $link = mysql_connect($info["host"] . ":" . $info["port"], $info["user_id"], $info["password"]) or die("ServerError:Could not connect to host '" . $info["host"] . "'");
    mysql_set_charset($info["charset"], $link);
    mysql_select_db($info["database"], $link) or die("ServerError:Could not find database '" . $info["database"] . "'");
    $query = sti_parse_query_parameters($query);
    $query_result = mysql_query($query, $link) or die("ServerError:Data not found");
    $columns = array();
    $tables = array();
    while ($column = mysql_fetch_field($query_result)) {
        array_push($columns, $column);
        if (strlen($column->table) > 0) {
            $tables[$column->table] = $column->table;
        }
    }
    $fields = array();
    foreach ($tables as $table) {
        $result = mysql_query("show columns from {$table}", $link);
        if ($result !== false) {
            while ($column = mysql_fetch_array($result)) {
                $field = (object) null;
                $field->table = $table;
                $field->name = $column["Field"];
                $field->type = $column["Type"];
                array_push($fields, $field);
                unset($field);
            }
            mysql_free_result($result);
        }
    }
    $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>";
    while ($row = mysql_fetch_assoc($query_result)) {
        $xml_output .= "<{$data_source_name}>";
        foreach ($columns as $column) {
            $value = $row[$column->name];
            $column_type = sti_mysql_get_column_type($fields, $column);
            if ($column_type == "base64Binary") {
                $value = base64_encode($value);
            } else {
                if ($column_type == "boolean") {
                    if ($value != 0) {
                        $value = "true";
                    } else {
                        $value = "false";
                    }
                } else {
                    $value = str_replace("&", "&amp;", $value);
                    $value = str_replace("<", "&lt;", $value);
                    $value = str_replace(">", "&gt;", $value);
                }
            }
            $xml_output .= "<{$column->name}>{$value}</{$column->name}>";
        }
        $xml_output .= "</{$data_source_name}>";
    }
    $xml_output .= "</Database>";
    mysql_free_result($query_result);
    mysql_close($link);
    return $xml_output;
}
Example #3
0
function sti_mssql_query($query, $link)
{
    $query = sti_parse_query_parameters($query);
    if (function_exists("mssql_query")) {
        $result = mssql_query($query, $link) or die("ServerError:Data not found");
    } else {
        $result = sqlsrv_query($link, $query) or die("ServerError:Data not found");
    }
    return $result;
}
Example #4
0
function sti_oracle_get_data($connection_string, $data_source_name, $query)
{
    $info = sti_oracle_parse_connection_string($connection_string);
    if ($info["privilege"] == "") {
        $conn = oci_connect($info["user_id"], $info["password"], $info["database"], $info["charset"]);
    } else {
        $conn = oci_pconnect($info["user_id"], $info["password"], $info["database"], $info["charset"], $info["privilege"]);
    }
    if ($conn === false) {
        $err = ocierror();
        return "ServerError:Could not connect {$err['message']}";
    }
    $query = sti_parse_query_parameters($query);
    $stmt = oci_parse($conn, $query);
    if ($stmt === false) {
        $err = oci_error($conn);
        return "ServerError:Parse Error {$err['message']}";
    } else {
        if (strpos($query, "cursor") !== false) {
            $curs = oci_new_cursor($conn);
            oci_bind_by_name($stmt, "cursor", $curs, -1, OCI_B_CURSOR);
        }
        if (oci_execute($stmt, OCI_COMMIT_ON_SUCCESS) === true) {
            if (isset($curs)) {
                if (oci_execute($curs, OCI_DEFAULT) === false) {
                    $err = oci_error();
                    return "ServerError:Cursor Execute Error {$err['message']}";
                }
                $stmt_curs = $curs;
            } else {
                $stmt_curs = $stmt;
            }
            $ncols = oci_num_fields($stmt_curs);
            $column_names = array();
            $column_types = array();
            for ($i = 1; $i <= $ncols; $i++) {
                $column_names[] = oci_field_name($stmt_curs, $i);
                $column_type = oci_field_type($stmt_curs, $i);
                $column_precision = oci_field_precision($stmt_curs, $i);
                $column_types[] = sti_oracle_get_column_type($column_type, $column_precision);
            }
            $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>";
            oci_fetch_all($stmt_curs, $data);
            for ($i = 0; $i < count($data[$column_names[0]]); $i++) {
                $xml_output .= "<{$data_source_name}>";
                for ($j = 0; $j < count($column_names); $j++) {
                    $value = $data[$column_names[$j]][$i];
                    if ($column_types[$j] == "base64Binary") {
                        $value = base64_encode($value);
                    }
                    if ($column_types[$j] == "dateTime" && strlen($value) > 0 && strpos($value, ".") > 0) {
                        $values = preg_split("/\\./", $value);
                        if (count($values) >= 3) {
                            if (strlen($values[2]) > 2) {
                                $value = $values[2] . '-' . $values[1] . '-' . $values[0];
                            } else {
                                $value = ((int) $values[2] >= 30 ? '19' . $values[2] : '20' . $values[2]) . '-' . $values[1] . '-' . $values[0];
                            }
                        }
                    } else {
                        $value = str_replace("&", "&amp;", $value);
                        $value = str_replace("<", "&lt;", $value);
                        $value = str_replace(">", "&gt;", $value);
                    }
                    $xml_output .= "<{$column_names[$j]}>{$value}</{$column_names[$j]}>";
                }
                $xml_output .= "</{$data_source_name}>";
            }
            $xml_output .= "</Database>";
            if (isset($curs)) {
                oci_free_statement($curs);
            }
            oci_free_statement($stmt);
        } else {
            $err = ocierror($stmt);
            return "ServerError:Execute Error {$err['message']} {$query}";
        }
    }
    return $xml_output;
}
Example #5
0
function sti_odbc_get_data($connection_string, $data_source_name, $query)
{
    $info = sti_odbc_parse_connection_string($connection_string);
    $link = odbc_connect($info["dsn"], $info["user_id"], $info["password"]) or die("ServerError:Could not connect to host");
    $query = sti_parse_query_parameters($query);
    $result = odbc_exec($link, $query) or die("ServerError:Data not found");
    $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>";
    odbc_fetch_row($result, 0);
    $count = odbc_num_fields($result);
    for ($fid = 1; $fid <= $count; $fid++) {
        $columns[$fid] = odbc_field_name($result, $fid);
    }
    while (odbc_fetch_row($result)) {
        $xml_output .= "<{$data_source_name}>";
        for ($fid = 1; $fid <= $count; $fid++) {
            $column = $columns[$fid];
            $value = odbc_result($result, $column);
            $field_type = odbc_field_type($result, $fid);
            $column_type = sti_odbc_get_column_type($field_type);
            if ($column_type == "base64Binary") {
                $value = base64_encode($value);
            } else {
                $value = str_replace("&", "&amp;", $value);
                $value = str_replace("<", "&lt;", $value);
                $value = str_replace(">", "&gt;", $value);
            }
            $xml_output .= "<{$column}>{$value}</{$column}>";
        }
        $xml_output .= "</{$data_source_name}>";
    }
    $xml_output .= "</Database>";
    odbc_free_result($result);
    odbc_close($link);
    return $xml_output;
}