コード例 #1
0
            return;
        }
        /* free the result */
        CreateXMLFromResult($mysql, $value);
        if ($value['result'] !== 1) {
            yog_mysql_free_result($value['result']);
        }
    }
    WriteLog("Exit ExecuteSingleQuery");
}
function CreateXMLFromResult($mysql, $value)
{
    // $value['result'], $value['ar']
    /* query execute was successful so we need to echo the correct xml */
    /* the query may or may not return any result */
    WriteLog("yog_mysql_num_rows in ExecuteSingleQuery");
    // check if the query is not a result returning query
    $isNotResultQuery = 0;
    if (DB_EXTENSION == "mysqli") {
        $value['result'] === 1 ? $isNotResultQuery = 1 : ($isNotResultQuery = 0);
    } else {
        $value['result'] == 1 ? $isNotResultQuery = 1 : ($isNotResultQuery = 0);
    }
    $numrows = 0;
    $numfields = 0;
    if (!is_int($value['result'])) {
        $numrows = yog_mysql_num_rows($value['result']);
        $numfields = yog_mysql_num_fields($value['result']);
    }
    if ($isNotResultQuery || !$numrows && !$numfields) {
        /* is a non-result query */
        echo "<result v=\"" . tunnelversion . "\">";
        echo "<e_i></e_i>";
        HandleExtraInfo($mysql, $value);
        echo "<f_i c=\"0\"></f_i><r_i></r_i></result>";
        return;
    }
    /* handle result query like SELECT,SHOW,EXPLAIN or DESCRIBE */
    echo '<result v="' . tunnelversion . '">';
    echo "<e_i></e_i>";
    /* add some extra info */
    HandleExtraInfo($mysql, $value);
    /* add the field count information */
    $fieldcount = yog_mysql_num_fields($value['result']);
    print $fieldcount;
    echo "<f_i c=\"{$fieldcount}\">";
    /* retrieve information about each fields */
    $i = 0;
    while ($i < $fieldcount) {
        $meta = yog_mysql_fetch_field($value['result']);
        echo "<f>";
        echo "<n>" . convertxmlchars($meta->name) . "</n>";
        echo "<t>" . convertxmlchars($meta->table) . "</t>";
        echo "<m>" . convertxmlchars($meta->max_length) . "</m>";
        echo "<d></d>";
        switch (DB_EXTENSION) {
            case "mysql":
                echo "<ty>" . GetCorrectDataType($value['result'], $i) . "</ty>";
                break;
            case "mysqli":
                echo "<ty>" . yog_mysql_field_type($value['result'], $i) . "</ty>";
                break;
        }
        echo "</f>";
        $i++;
    }
    /* end field informations */
    echo "</f_i>";
    /* get information about number of rows in the resultset */
    echo "<r_i c=\"{$numrows}\">";
    /* add up each row information */
    while ($row = yog_mysql_fetch_array($value['result'])) {
        $lengths = yog_mysql_fetch_lengths($value['result']);
        /* start of a row */
        echo "<r>";
        for ($i = 0; $i < $fieldcount; $i++) {
            /* start of a col */
            echo "<c l=\"{$lengths[$i]}\">";
            if (!isset($row[$i])) {
                echo "(NULL)";
            } else {
                if ($lengths[$i] == 0) {
                    echo "_";
                } else {
                    echo convertxmlchars(base64_encode($row[$i]));
                }
コード例 #2
0
ファイル: sqly.php プロジェクト: juliogallardo1326/proc
function ExecuteSingleQuery($mysql, $query)
{
    global $tunnelversion;
    $result = mysql_query($query, $mysql);
    WriteLog("Enter ExecuteSingleQuery");
    if (!$result) {
        HandleError(mysql_errno(), mysql_error());
        return;
    }
    /* query execute was successful so we need to echo the correct xml */
    /* the query may or may not return any result */
    WriteLog("mysql_num_rows in ExecuteSingleQuery");
    if (!mysql_num_rows($result) && !mysql_num_fields($result)) {
        /* is a non-result query */
        echo "<xml v=\"" . $tunnelversion . "\">";
        echo "<e_i></e_i>";
        HandleExtraInfo($mysql);
        echo "<f_i c=\"0\"></f_i><r_i></r_i></xml>";
        return;
    }
    /* handle result query like SELECT,SHOW,EXPLAIN or DESCRIBE */
    echo '<xml v="' . $tunnelversion . '">';
    echo "<e_i></e_i>";
    /* add some extra info */
    HandleExtraInfo($mysql);
    /* add the field count information */
    $fieldcount = mysql_num_fields($result);
    print $fieldcount;
    echo "<f_i c=\"{$fieldcount}\">";
    /* retrieve information about each fields */
    $i = 0;
    while ($i < $fieldcount) {
        $meta = mysql_fetch_field($result);
        echo "<f>";
        echo "<n>" . convertxmlchars($meta->name) . "</n>";
        echo "<t>" . convertxmlchars($meta->table) . "</t>";
        echo "<m>" . convertxmlchars($meta->max_length) . "</m>";
        echo "<d></d>";
        echo "<ty>" . GetCorrectDataType($result, $i) . "</ty>";
        echo "</f>";
        $i++;
    }
    /* end field informations */
    echo "</f_i>";
    /* get information about number of rows in the resultset */
    $numrows = mysql_num_rows($result);
    echo "<r_i c=\"{$numrows}\">";
    /* add up each row information */
    while ($row = mysql_fetch_array($result)) {
        $lengths = mysql_fetch_lengths($result);
        /* start of a row */
        echo "<r>";
        for ($i = 0; $i < $fieldcount; $i++) {
            /* start of a col */
            echo "<c l=\"{$lengths[$i]}\">";
            if (!isset($row[$i])) {
                echo "(NULL)";
            } else {
                if (mysql_field_type($result, $i) == "blob") {
                    if ($lengths[$i] == 0) {
                        echo "_";
                    } else {
                        echo convertxmlchars(base64_encode($row[$i]));
                    }
                } else {
                    if ($lengths[$i] == 0) {
                        echo "_";
                    } else {
                        echo convertxmlchars($row[$i]);
                    }
                }
            }
            /* end of a col */
            echo "</c>";
        }
        /* end of a row */
        echo "</r>";
    }
    /* close the xml output */
    echo "</r_i></xml>";
    /* free the result */
    mysql_free_result($result);
    WriteLog("Exit ExecuteSingleQuery");
}