示例#1
0
function exeQueryA($SQL, &$aData, &$Errors, $printFields = false)
{
    $aData = array();
    $nData = 0;
    $Errors = "";
    $result = PG_QueryStart($SQL, $aFields, $link, $Errors);
    if (!($result === false)) {
        while ($qRow = pg_fetch_array($result, null, PGSQL_NUM)) {
            $aData[$qRow[0]] = $qRow;
            $nData++;
        }
    }
    PG_QueryEnd($link, $result);
    if ($Errors != "") {
        $nData = -1;
    }
    // echo "\n<!-- $SQL ==> $nData -->\n";
    return $nData;
}
示例#2
0
function Load_Data2JSON($SQL, $sName = "", $bShowError = true, $noHeader = true)
{
    $nFD = fopen("Load_Data2JSOS.trc", "a");
    if ($nFD > 0) {
        $sTime = strftime("%Y-%m-%d %H:%M:%S", time());
        fputs($nFD, "{$sTime} | {$SQL}\n");
        fclose($nFD);
    }
    $Errors = "";
    $JSON = "";
    $nData = 0;
    $result = PG_QueryStart($SQL, $aFields, $link, $Errors);
    if (!($result === false)) {
        $nFields = count($aFields);
        if (!$noHeader) {
            $JSON .= "{\n\t \"name\": \"" . $sName . "\",\n\t \"items\":[\n ";
        }
        while ($qRow = pg_fetch_array($result, null, PGSQL_NUM)) {
            if ($nData > 0) {
                $JSON .= ",\n";
            }
            $JSON .= "\t{\n";
            for ($j = 0; $j < $nFields; $j++) {
                $sVal = "" . $qRow[$j];
                $JSON .= "\t\t\"" . htmlspecialchars($aFields[$j][0]) . "\": \"" . htmlspecialchars($sVal) . "\"";
                if ($j < $nFields - 1) {
                    $JSON .= ",\n";
                }
            }
            $JSON .= "\n\t}";
            $nData++;
        }
        if (!$noHeader) {
            $JSON .= "]}";
        }
    }
    PG_QueryEnd($link, $result);
    return $JSON;
}