public function closeConnection() { $this->freeResults(); if ($this->connection != null) { pg_Close($this->connection); } }
function StandaloneQuery(&$db, $query) { if (($connection = $db->DoConnect("template1", 0)) == 0) { return 0; } if (!($success = @pg_Exec($connection, "{$query}"))) { $db->SetError("Standalone query", pg_ErrorMessage($connection)); } pg_Close($connection); return $success; }
function Setup() { if (!function_exists("pg_connect")) { return "PostgreSQL support is not available in this PHP configuration"; } $this->supported["Sequences"] = $this->supported["Indexes"] = $this->supported["SummaryFunctions"] = $this->supported["OrderByText"] = $this->supported["Transactions"] = $this->supported["GetSequenceCurrentValue"] = $this->supported["SelectRowRanges"] = $this->supported["LOBs"] = $this->supported["Replace"] = $this->supported["AutoIncrement"] = $this->supported["PrimaryKey"] = $this->supported["OmitInsertKey"] = $this->supported["OmitInsertKey"] = $this->supported["PatternBuild"] = 1; if (function_exists("pg_cmdTuples")) { if ($connection = $this->DoConnect("template1", 0)) { if ($result = @pg_Exec($connection, "BEGIN")) { $error_reporting = error_reporting(63); @pg_cmdTuples($result); if (!isset($php_errormsg) || strcmp($php_errormsg, "This compilation does not support pg_cmdtuples()")) { $this->supported["AffectedRows"] = 1; } error_reporting($error_reporting); } else { $this->SetError("Setup", pg_ErrorMessage($connection)); } pg_Close($connection); } else { $result = 0; } if (!$result) { return $this->Error(); } } if (isset($this->options["EmulateDecimal"]) && $this->options["EmulateDecimal"]) { $this->emulate_decimal = 1; $this->decimal_factor = pow(10.0, $this->decimal_places); } return ""; }
function pg_db_close($iBanco) { $bFechou = @pg_Close($iBanco); return $bFechou; }
/** * execute a query * * @param string $query * @return * @access private */ function _standaloneQuery($query) { if (($connection = $this->_doConnect('template1', 0)) == 0) { return $this->raiseError(MDB_ERROR_CONNECT_FAILED, NULL, NULL, '_standaloneQuery: Cannot connect to template1'); } if (!($result = @pg_Exec($connection, $query))) { $this->raiseError(MDB_ERROR, NULL, NULL, '_standaloneQuery: ' . @pg_errormessage($connection)); } pg_Close($connection); return $result; }
function dumpPGQueryResults($queryStr) { $layerDataList = $this->glayer->getLayerDbProperties(); $geom = $layerDataList['geocol']; $dbtable = $layerDataList['dbtable']; $unique_field = $layerDataList['unique_field']; // Load PGSQL extension if necessary if (PHP_OS == "WINNT" || PHP_OS == "WIN32") { if (!extension_loaded('pgsql')) { if (function_exists("dl")) { dl('php_pgsql.' . PHP_SHLIB_SUFFIX); } else { error_log("P.MAPPER ERROR: This version of PHP does support the 'dl()' function. Please enable 'php_pgsql.dll' in your php.ini"); return false; } } } // CONNECT TO DB $connString = $this->qLayer->connection; if (!($connection = pg_Connect($connString))) { error_log("P.MAPPER: Could not connect to database"); error_log("P.MAPPER: PG Connection error: " . pg_last_error($connection)); exit; } // FIELDS and FIELD HEADERS for result $selFields = $this->glayer->getResFields(); $s = ''; foreach ($selFields as $f) { $s .= "{$f},"; } // Select string for DB query $select = substr($s, 0, -1); // Apply already existing filter on layer $pg_filter = trim(str_replace('"', '', $this->qLayer->getFilterString())); if (strlen($pg_filter) > 2 && $pg_filter != "(null)") { if (strlen($queryStr)) { $queryStr = "({$queryStr}) AND ({$pg_filter}) "; } else { $queryStr = " {$pg_filter} "; } } // Limit search to limit set in INI file $searchlimit = $this->limitResult + 1; // RUN DB DEFINE QUERY $query = "SELECT {$unique_field}, \n ST_xmin(box3d({$geom})), \n ST_ymin(box3d({$geom})), \n ST_xmax(box3d({$geom})), \n ST_ymax(box3d({$geom})), \n {$select} \n FROM {$dbtable} \n WHERE {$queryStr}\n LIMIT {$searchlimit}"; pm_logDebug(3, $query, "P.MAPPER-DEBUG: squery.php/dumpPGQueryResults() - SQL Cmd:"); $qresult = pg_query($connection, $query); if (!$qresult) { error_log("P.MAPPER: PG Query error for : {$query}" . pg_result_error($qresult)); } $numrows = min(pg_numrows($qresult), $this->limitResult); $this->numResults = $numrows; // CREATE HTML OUPTPUT if ($numrows > 0) { if ($this->zoomFull) { // Maximum start extents $mExtMinx = 999999999; $mExtMiny = 999999999; $mExtMaxx = -999999999; $mExtMaxy = -999999999; } // Fetch records from db and print them out for ($r = 0; $r < $numrows; ++$r) { $a = pg_fetch_row($qresult, $r); $a_rows = count($a); $qShpIdx = $a[0]; $oids[] = $qShpIdx; // If map and layer have different proj, re-project extents if ($this->changeLayProj) { $pb = $this->reprojectExtent($a); $xmin = $pb['shpMinx']; $ymin = $pb['shpMiny']; $xmax = $pb['shpMaxx']; $ymax = $pb['shpMaxy']; } else { $xmin = $a[1]; $ymin = $a[2]; $xmax = $a[3]; $ymax = $a[4]; } // Set buffer for zoom extent if ($this->qLayerType == 0) { $buf = $this->pointBuffer; // set buffer depending on dimensions of your coordinate system } else { if (isset($this->shapeQueryBuffer) && $this->shapeQueryBuffer > 0) { $buf = $this->shapeQueryBuffer * (($xmax - $xmin + ($ymax - $ymin)) / 2); } else { $buf = 0; } } if ($buf > 0) { $xmin -= $buf; $ymin -= $buf; $xmax += $buf; $ymax += $buf; } // Look for min/max extents of ALL features if ($this->zoomFull) { $mExtMinx = min($mExtMinx, $xmin); $mExtMiny = min($mExtMiny, $ymin); $mExtMaxx = max($mExtMaxx, $xmax); $mExtMaxy = max($mExtMaxy, $ymax); } // Output JSON //$qShpLink = "{\"shplink\": [" . ($this->zoomFull ? "\"0\",\"0" : "\"" . $this->qLayerName ."\",\"".$qShpIdx) ."\",\"". $xmin ."+". $ymin ."+". $xmax ."+". $ymax ."\"]}"; $qShpLink = "{\"shplink\": [\"" . $this->qLayerName . "\",\"" . $qShpIdx . "\",\"" . $xmin . "+" . $ymin . "+" . $xmax . "+" . $ymax . "\"" . ($this->zoomFull ? ",1" : ",0") . "]}"; // print SHAPEINDEX link $this->qStr .= "[" . $qShpLink; // Print all OTHER FIELDS for ($i = 5; $i < $a_rows; ++$i) { //printFieldValues($glayer, $qlayerName, $fldName, $a[$i]); $fldName = pg_field_name($qresult, $i); $this->qStr .= $this->printFieldValues($fldName, $a[$i]); } $this->qStr .= "]"; if ($r < $numrows - 1) { $this->qStr .= ", "; } //$this->qStr .= "\n"; } // Full extent for ALL features if ($this->zoomFull) { $this->maxExtent = array($mExtMinx, $mExtMiny, $mExtMaxx, $mExtMaxy); } else { $this->maxExtent = 0; } $this->resultindexes = $oids; } pg_Close($connection); }