function show_css_page($dbconn, $diary_login) { $sql = "SELECT u.uid, s.page_css FROM " . TABLE_SETTINGS . " AS s, " . TABLE_USERS . " AS u WHERE u.login='******' AND s.uid=u.uid LIMIT 1"; $result = pg_query($dbconn, $sql) or die(pg_last_error($dbconn)); $data = pg_fetch_object($result, NULL); echo $data->page_css; }
function sql_query($sqltype, $query, $con) { if ($sqltype == 'mysql') { if (class_exists('mysqli')) { return $con->query($query); } elseif (function_exists('mysql_query')) { return mysql_query($query); } } elseif ($sqltype == 'mssql') { if (function_exists('sqlsrv_query')) { return sqlsrv_query($con, $query); } elseif (function_exists('mssql_query')) { return mssql_query($query); } } elseif ($sqltype == 'pgsql') { return pg_query($query); } elseif ($sqltype == 'oracle') { return oci_execute(oci_parse($con, $query)); } elseif ($sqltype == 'sqlite3') { return $con->query($query); } elseif ($sqltype == 'sqlite') { return sqlite_query($con, $query); } elseif ($sqltype == 'odbc') { return odbc_exec($con, $query); } elseif ($sqltype == 'pdo') { return $con->query($query); } }
/** * Взять информацию по найденным результатам * * @return array массив с пользователями */ function getRecords($order_by = NULL) { if ($this->matches) { $sql = "SELECT * FROM search_users_simple WHERE id IN (" . implode(', ', $this->matches) . ')'; if ($order_by) { $sql .= " ORDER BY {$order_by}"; } else { if ($this->_sortby && (($desc = $this->_sort == SPH_SORT_ATTR_DESC) || $this->_sort == SPH_SORT_ATTR_ASC)) { $sql .= " ORDER BY {$this->_sortby}" . ($desc ? ' DESC' : ''); } } if ($res = pg_query(DBConnect(), $sql)) { if (!$order_by && ($this->_sort == SPH_SORT_RELEVANCE || $this->_sort == SPH_SORT_EXTENDED)) { $links = array(); $rows = array(); while ($row = pg_fetch_assoc($res)) { $links[$row['id']] = $row; } for ($i = 0; $i < count($this->matches); $i++) { $rows[] = $links[$this->matches[$i]]; } } else { $rows = pg_fetch_all($res); } return $rows; } } return array(); }
public function query($query) { if ($this->connection === null) { $this->connect(); } try { $result = pg_query($this->connection, $query); } catch (Exception $e) { if (preg_match("/^pg_query\\(\\): Query failed: ERROR: null value in column (\\S+) violates not-null constraint/", $e->getMessage(), $matches)) { throw new Atrox_Core_Exception_NullValueException($matches[1] . " can not be null"); } else { if (preg_match("/^pg_query\\(\\): Query failed: ERROR: duplicate key violates unique constraint/", $e->getMessage())) { throw new Atrox_Core_Data_Exception_DuplicateKeyException($e->getMessage()); } else { if (preg_match("/^pg_query\\(\\): Query failed: ERROR: relation \"(\\S+)\" does not exist/", $e->getMessage(), $matches)) { throw new Atrox_Core_Exception_NoSuchRelationException($e->getMessage()); } else { if (preg_match("/^pg_query\\(\\): Query failed: ERROR: value (\\S+) is out of range for type (\\S+)/", $e->getMessage(), $matches)) { throw new Atrox_Core_Exception_OutOfRangeException($matches[1] . " is not within range of datatype '{$matches[2]}'"); } else { if (preg_match("/^pg_query\\(\\): Query failed: ERROR: value too long for type (.+)/", $e->getMessage(), $matches)) { throw new Atrox_Core_Exception_TooLongException("Value is too long for datatype '{$matches[1]}'"); } else { throw $e; } } } } } } return $result; }
public function query($sql) { $resource = pg_query($this->link, $sql); if ($resource) { if (is_resource($resource)) { $i = 0; $data = array(); while ($result = pg_fetch_assoc($resource)) { $data[$i] = $result; $i++; } pg_free_result($resource); $query = new \stdClass(); $query->row = isset($data[0]) ? $data[0] : array(); $query->rows = $data; $query->num_rows = $i; unset($data); return $query; } else { return true; } } else { trigger_error('Error: ' . pg_result_error($this->link) . '<br />' . $sql); exit; } }
public function query($query) { if ($this->ok()) { $this->resource = pg_query($this->connection, $query); } return $this->resource !== false; }
function Header() { //$dados = @pg_exec("select nomeinst,ender,munic,uf,telef,email,url,logo from db_config where codigo = ".@$GLOBALS["DB_instit"]); //$url = @pg_result($dados,0,"url"); //global $nomeinst; //$nomeinst = pg_result($dados,0,"nomeinst"); //global $ender; //$ender = pg_result($dados,0,"ender"); $sql = "select nomeinst,bairro,cgc,ender,upper(munic) as munic,uf,telef,email,url,logo, db12_extenso\n\t\tfrom db_config \n\t\tinner join db_uf on db12_uf = uf\n\t\twhere codigo = " . db_getsession("DB_instit"); $result = pg_query($sql); global $nomeinst; global $ender; global $munic; global $cgc; global $bairro; global $uf; //echo $sql; db_fieldsmemory($result, 0); /// seta a margem esquerda que veio do relatorio $S = $this->lMargin; $this->SetLeftMargin(10); $Letra = 'Times'; $this->Image("imagens/files/logo_boleto.png", 95, 8, 24); //$this->Image('imagens/files/'.$logo,2,3,30); $this->Ln(35); $this->SetFont($Letra, '', 10); $this->MultiCell(0, 4, $db12_extenso, 0, "C", 0); $this->SetFont($Letra, 'B', 13); $this->MultiCell(0, 6, $nomeinst, 0, "C", 0); $this->SetFont($Letra, 'B', 12); $this->MultiCell(0, 4, @$GLOBALS["head1"], 0, "C", 0); $this->Ln(10); $this->SetLeftMargin($S); }
public static function GetChannels() { global $recent; $list = array(); if (isset($_GET['recent'])) { if ($_GET['recent'] == "yes") { $recent = true; } else { $recent = false; } setcookie("recent", $_GET["recent"]); } if ($recent === NULL && isset($_COOKIE['recent']) && $_COOKIE['recent'] == "yes") { $recent = true; } if ($recent) { $query = pg_query("SELECT channel FROM active ORDER by channel"); } else { $query = pg_query("SELECT channel FROM logs_meta WHERE name = 'enabled' AND value = 'True' ORDER by channel"); } while ($item = pg_fetch_assoc($query)) { $list[] = $item["channel"]; } return $list; }
function consultarUsuarioLoginSenha($name, $password, $conn) { $query = "SELECT DISTINCT\n\t\t\t\t\t*\n\t\t\t\t FROM \n\t\t\t\t\tusuarios u\n\t\t\t\t WHERE\n\t\t\t\t\tu.nome = '" . $name . "' AND\n\t\t\t\t\tu.senha = '" . $password . "'"; $queryResut = pg_query($conn, $query); $queryResut = pg_fetch_array($queryResut); return $queryResut; }
function control() { global $result, $input, $userID; $conn = pg_connect("host=postgredb.ctnfr2pmdvmf.us-west-2.rds.amazonaws.com port=5432 dbname=postgreDB user=postgreuser password=6089qwerty"); if (!$conn) { echo "denied, an error occurred about connection.\n"; exit; } $query = "SELECT USERNAME,USERID FROM PALUSER WHERE USERNAME LIKE '{$input}%' AND USERID != '{$userID}'"; $result = pg_query($conn, $query); if (!$result) { echo "denied, an error occurred about query.\n"; return 0; } $names = ""; $ids = ""; $first = true; while ($row = pg_fetch_row($result)) { if ($first) { $names = $row[0]; $ids = $row[1]; $first = false; } else { $names = $names . " " . $row[0]; $ids = $ids . " " . $row[1]; } } if ($ids == "") { echo "denied, empty result"; } return $names . " " . $ids; }
function query_start($query) { // For reg expressions $query = trim($query); // Query was an insert, delete, update, replace if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) { return false; } // Flush cached values.. $this->flush(); // Log how the function was called $this->func_call = "\$db->query_start(\"{$query}\")"; // Keep track of the last query for debug.. $this->last_query = $query; // Perform the query via std pg_query function.. if (!($this->result = @pg_query($this->dbh, $query))) { $this->print_error(); return false; } $this->num_queries++; // ======================================================= // Take note of column info $i = 0; while ($i < @pg_num_fields($this->result)) { $this->col_info[$i]->name = pg_field_name($this->result, $i); $this->col_info[$i]->type = pg_field_type($this->result, $i); $this->col_info[$i]->size = pg_field_size($this->result, $i); $i++; } $this->last_result = array(); $this->num_rows = 0; // If debug ALL queries $this->trace || $this->debug_all ? $this->debug() : null; return true; }
function get_node_map($node, $node_old) { global $table_cable; global $table_pq; global $table_node; global $title; global $table_cable_type; $sql = "SELECT n1.id AS node_id_1, n2.id AS node_id_2, n1.address AS n1, n2.address AS n2, n1.id AS n1_id, n2.id AS n2_id, c_t.name AS cable_name, c_t.fib AS cable_fib\r\n FROM " . $table_pq . " AS p1, " . $table_pq . " AS p2, " . $table_cable . " AS c1, " . $table_node . " AS n1, " . $table_node . " AS n2, " . $table_cable_type . " AS c_t\r\n WHERE " . (isset($_GET['id']) ? "p1.node = " . $node . " AND p2.node != " . $node_old . " AND" : "") . " p2.id = CASE WHEN c1.pq_1 = p1.id THEN c1.pq_2 ELSE CASE WHEN c1.pq_2 = p1.id THEN c1.pq_1 ELSE NULL END END\r\n AND p1.node = n1.id\r\n AND p2.node = n2.id\r\n \tAND c1.cable_type = c_t.id"; //echo $sql.'<br>'; //die; $result = pg_query($sql); if (pg_num_rows($result)) { while ($row = pg_fetch_assoc($result)) { if ($node_old == 0) { $title = $row['n1']; } if (isset($_GET['id'])) { if (add_arr($row['node_id_1'], $row['node_id_2'], $row['n1_id'], $row['n2_id'], $row['n1'], $row['n2'], $row['cable_name'], $row['cable_fib']) && $row['n2_id']) { get_node_map($row['n2_id'], $row['n1_id']); } } else { add_arr($row['node_id_1'], $row['node_id_2'], $row['n1_id'], $row['n2_id'], $row['n1'], $row['n2'], $row['cable_name'], $row['cable_fib']); } } } return $content; }
function get_attributes() { $sql_str = "SELECT " . "name, " . "style_desc, " . "symbol_name, " . "symbol_size, " . "angle, " . "width, " . "color_r, " . "color_g, " . "color_b, " . "outlinecolor_r, " . "outlinecolor_b, " . "outlinecolor_g, " . "bgcolor_r, " . "bgcolor_g, " . "bgcolor_b " . "FROM " . "tng_mapserver_style " . "WHERE " . "id = " . $this->id; $this->dbconn->connect(); $result = pg_query($this->dbconn->conn, $sql_str); if (!$result) { echo "An error occurred while executing the query - " . $sql_str . " - " . pg_last_error($this->dbconn->conn); //$this->dbconn->disconnect(); return false; } // successfuly ran the query // store attributes $this->name = pg_fetch_result($result, 0, 'name'); $this->style_desc = pg_fetch_result($result, 0, 'style_desc'); $this->symbol_name = pg_fetch_result($result, 0, 'symbol_name'); $this->symbol_size = pg_fetch_result($result, 0, 'symbol_size'); $this->angle = pg_fetch_result($result, 0, 'angle'); $this->width = pg_fetch_result($result, 0, 'width'); $this->color_r = pg_fetch_result($result, 0, 'color_r'); $this->color_g = pg_fetch_result($result, 0, 'color_g'); $this->color_b = pg_fetch_result($result, 0, 'color_b'); $this->outlinecolor_r = pg_fetch_result($result, 0, 'outlinecolor_r'); $this->outlinecolor_g = pg_fetch_result($result, 0, 'outlinecolor_g'); $this->outlinecolor_b = pg_fetch_result($result, 0, 'outlinecolor_b'); $this->bgcolor_r = pg_fetch_result($result, 0, 'bgcolor_r'); $this->bgcolor_g = pg_fetch_result($result, 0, 'bgcolor_g'); $this->bgcolor_b = pg_fetch_result($result, 0, 'bgcolor_b'); $this->dbconn->disconnect(); return true; }
function transform($x, $y, $oldEPSG, $newEPSG) { if (is_null($x) || !is_numeric($x) || is_null($y) || !is_numeric($y) || is_null($oldEPSG) || !is_numeric($oldEPSG) || is_null($newEPSG) || !is_numeric($newEPSG)) { return null; } if (SYS_DBTYPE == 'pgsql') { $con = db_connect(DBSERVER, OWNER, PW); $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as minx"; $resMinx = db_query($sqlMinx); $minx = floatval(db_result($resMinx, 0, "minx")); $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as miny"; $resMiny = db_query($sqlMiny); $miny = floatval(db_result($resMiny, 0, "miny")); } else { $con_string = "host=" . GEOS_DBSERVER . " port=" . GEOS_PORT . " dbname=" . GEOS_DB . "user="******"password="******"Error while connecting database"); /* * @security_patch sqli done */ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as minx"; $resMinx = pg_query($con, $sqlMinx); $minx = floatval(pg_fetch_result($resMinx, 0, "minx")); $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as miny"; $resMiny = pg_query($con, $sqlMiny); $miny = floatval(pg_fetch_result($resMiny, 0, "miny")); } return array("x" => $minx, "y" => $miny); }
public function postprocess_event($event) { $savepoint = $this->get_savepoint($event); switch ($event->tag) { case PGQ_EVENT_OK: $sql_release = sprintf("RELEASE SAVEPOINT %s", $savepoint); $this->log->debug($sql_release); $result = pg_query($this->pg_dst_con, $sql_release); if ($result === False) { $this->log->notice("Could not release savepoint %s", $savepoint); return PGQ_ABORT_BATCH; } break; case PGQ_EVENT_FAILED: $sql_rollback = sprintf("ROLLBACK TO SAVEPOINT %s", $savepoint); $this->log->debug($sql_rollback); $result = pg_query($this->pg_dst_con, $sql_rollback); if ($result === False) { $this->log->notice("Could not rollback to savepoint %s", $savepoint); return PGQ_ABORT_BATCH; } break; case PGQ_EVENT_RETRY: $sql_rollback = sprintf("ROLLBACK TO SAVEPOINT %s", $savepoint); $this->log->debug($sql_rollback); $result = pg_query($this->pg_dst_con, $sql_rollback); if ($result === False) { $this->log->notice("Could not tollback to savepoint %s", $savepoint); return PGQ_ABORT_BATCH; } break; } return True; }
protected function db_query($sql) { $this->db_link(); $result = pg_query($this->dblink, $sql); $this->db_close(); return $result; }
function db_savesession($_conn, $_session) { // Cria tabela temporaria para a conexao corrente $sql = "SELECT fc_startsession();"; $result = pg_query($_conn, $sql) or die("Não foi possível criar sessão no banco de dados (Sql: {$sql})!"); if (pg_num_rows($result) == 0) { return false; } // Insere as variaveis da sessao na tabela $sql = ""; foreach ($_session as $key => $val) { $key = strtoupper($key); // Intercepta "DB_DATAUSU" para ajustes if ($key == "DB_DATAUSU") { $time = microtime(true); $micro_time = sprintf("%06d", ($time - floor($time)) * 1000000); $time_now = date("H:i:s"); $datahora = date("Y-m-d {$time_now}.{$micro_time}O", $val); // Cria timestamp "DB_DATAHORAUSU" $sql .= "SELECT fc_putsession('DB_DATAHORAUSU', '{$datahora}'); "; $val = date("Y-m-d", $val); } if (substr($key, 0, 2) == "DB") { $val = addslashes($val); $sql .= "SELECT fc_putsession('{$key}', '{$val}'); "; } } pg_query($_conn, $sql) or die("Não foi possível criar sessão no banco de dados (Sql: {$sql})!"); return true; }
function getNextLogId() { $qry = "select nextval('techmatcher.subscriptiontransactionlog_sq')"; $result = pg_query($qry); $value = pg_fetch_row($result); return $value; }
public function advanceSearchForUser($owner, $item_number, $pos_review, $neg_review, $ownerSort, $activitySort) { $query = "SELECT a.username, a.display_pic, SUM(CASE WHEN a.value_type='review' THEN a.positive END) AS pos_review, SUM(CASE WHEN a.value_type='review' THEN a.negative END) AS neg_review, SUM(CASE WHEN a.value_type='item' THEN a.positive END) AS item FROM augmented_member a WHERE "; $ownerCondition = " TRUE "; if (isset($owner) && !empty($owner)) { $ownerCondition = " a.username LIKE '%{$owner}%' "; } $itemNumCondition = " TRUE "; if (isset($item_number) && !empty($item_number)) { $itemNumCondition = " EXISTS(SELECT * FROM augmented_member a1 \n WHERE a1.value_type = 'item' \n AND a1.positive >= {$item_number}\n AND a1.username = a.username) "; } $posNumCondition = " TRUE "; if (isset($pos_review) && !empty($pos_review)) { $posNumCondition = " EXISTS(SELECT * FROM augmented_member a2 \n WHERE a2.value_type = 'review' \n AND a2.positive >= {$pos_review}\n AND a2.username = a.username) "; } $negNumCondition = " TRUE "; if (isset($neg_review) && !empty($neg_review) && $neg_review != "unlimited") { $negNumCondition = " EXISTS(SELECT * FROM augmented_member a3 \n WHERE a3.value_type = 'review' \n AND a3.negative <= {$neg_review}\n AND a3.username = a.username) "; } $query = $query . $ownerCondition . " AND " . $itemNumCondition . " AND " . $posNumCondition . " AND " . $negNumCondition . " AND a.account_type = 'member' GROUP BY a.username, a.display_pic "; if (isset($ownerSort) && !empty($ownerSort) && isset($activitySort) && !empty($activitySort)) { $query = $query . " ORDER BY a.username " . $ownerSort . ", " . "SUM(*) as activity " . $activitySort . ";"; } else { if (isset($ownerSort) && !empty($ownerSort)) { $query = $query . " ORDER BY a.username " . $ownerSort . " "; } if (isset($activitySort) && !empty($activitySort)) { $query = $query . " ORDER BY SUM(a.positive) " . $activitySort . " "; } } return pg_fetch_all(pg_query($query)); }
function query($sql) { if (!empty($this->db) || $this->connect()) { return @pg_query($this->db, $sql); } return false; }
function processar($strTable, $strFields, $strWhere = '', $strOrderBy = '', $intLimit = '', $strGroupBy = '') { // número máximo de resultados exibidos por página $this->paginas['POR_PAGINA'] = $this->numero; $strQuery = 'SELECT ' . $strFields; if ($strTable) { $strQuery .= ' FROM '; if (is_array($strTable)) { foreach ($strTable as $tbl) { $strQuery .= $this->tblprefix . $tbl . ' '; } } else { $strQuery .= $this->tblprefix . $strTable; } } if ($strWhere) { $strQuery .= ' WHERE ' . $strWhere; } if ($strGroupBy) { $strQuery .= ' GROUP BY ' . $strGroupBy; } if ($strOrderBy) { $strQuery .= ' ORDER BY ' . $strOrderBy; } if ($intLimit) { $strQuery .= ' LIMIT ' . $intLimit; } $query = $strQuery; /// RETORNA O VALOR TOTAL, SEM LIMIT $this->mysql['TOTAL'] = $this->mysql['LINK'] ? pg_num_rows(pg_query($query, $this->mysql['LINK'])) : pg_num_rows(pg_query($query)); /// RETORNA A CONSULTA JÁ COM O LIMIT $this->mysql['QUERY'] = $query . " LIMIT " . $this->paginas['POR_PAGINA'] . " OFFSET " . ($this->paginas['PAGINA'] - 1) * $this->paginas['POR_PAGINA']; /// TOTAL DE PÁGINAS BASEADAS NO TOTAL DE RESULTADOS E NO MÁXIMO DE RESULTADOS POR PÁGINA $this->paginas['TOTAL'] = ceil($this->mysql['TOTAL'] / $this->paginas['POR_PAGINA']); }
function db_query($link, $query, $die_on_error = true) { if (DB_TYPE == "pgsql") { $result = pg_query($link, $query); if (!$result) { $query = htmlspecialchars($query); // just in case if ($die_on_error) { die("Query <i>{$query}</i> failed [{$result}]: " . ($link ? pg_last_error($link) : "No connection")); } } return $result; } else { if (DB_TYPE == "mysql") { $result = mysql_query($query, $link); if (!$result) { $query = htmlspecialchars($query); if ($die_on_error) { die("Query <i>{$query}</i> failed: " . ($link ? mysql_error($link) : "No connection")); } } return $result; } } }
function Header() { $this->AddFont('Amble-Regular'); $this->SetFont('Amble-Regular', '', 10); $fecha = date('Y-m-d', time()); $this->SetX(1); $this->SetY(1); $this->Cell(20, 5, $fecha, 0, 0, 'C', 0); $this->Cell(150, 5, "CLIENTE", 0, 1, 'R', 0); $this->SetFont('Arial', 'B', 16); $sql = pg_query("select ruc_empresa,nombre_empresa,propietario,telefono1,telefono2,direccion,correo,sitio_web,autorizacion_factura,autorizacion_factura,imagen from empresa where id_empresa = '" . $_SESSION['empresa_dow'] . "'"); while ($row = pg_fetch_row($sql)) { $this->Cell(190, 8, maxCaracter("EMPRESA: " . utf8_decode($row[1]), 50), 0, 1, 'C', 0); $this->Image('../empresa/img/' . $row[10], 5, 8, 40, 30); $this->SetFont('Amble-Regular', '', 10); $this->Cell(180, 5, maxCaracter("PROPIETARIO: " . utf8_decode($row[2]), 50), 0, 1, 'C', 0); $this->Cell(70, 5, maxCaracter("TEL.: " . utf8_decode($row[3]), 50), 0, 0, 'R', 0); $this->Cell(60, 5, maxCaracter("CEL.: " . utf8_decode($row[4]), 50), 0, 1, 'C', 0); $this->Cell(170, 5, maxCaracter("DIR.: " . utf8_decode($row[5]), 55), 0, 1, 'C', 0); $this->Cell(170, 5, maxCaracter("E-MAIL.: " . utf8_decode($row[6]), 55), 0, 1, 'C', 0); $this->Cell(170, 5, maxCaracter("SITIO WEB.: " . utf8_decode($row[7]), 55), 0, 1, 'C', 0); $this->Text(160, 30, maxCaracter("Nro Aut SRI.: " . utf8_decode($row[8]), 55), 0, 1, 'C', 0); $this->Text(150, 35, maxCaracter("Fecha Aut SRI.: " . utf8_decode($row[9]), 55), 0, 1, 'C', 0); $this->Text(70, 44, "OBLIGADO A LLEVAR CONTABILIDAD : SI", 0, 'C', 0); $this->SetFont('Amble-Regular', 'U', 14); $this->Text(85, 49, "LIBRO DIARIO", 0, 'C', 0); $this->Text(85, 49, "LIBRO DIARIO", 0, 'C', 0); } $this->SetDrawColor(0, 0, 0); $this->SetLineWidth(0.5); $this->Line(1, 53, 210, 53); $this->Ln(16); }
function executeQuery($query) { //echo $query; $this->initConnection($this->connectionIndex); $this->results = pg_query($this->connection, $query); return $this->results; }
function query($sql) { $conect = conectarse(); $res = pg_query($sql) or die("Error en la consulta"); //pg_close($conect); return $res; }
protected function get_new_id() { $res = pg_query($this->connection, "SELECT LASTVAL() AS seq"); $data = pg_fetch_assoc($res); pg_free_result($res); return $data['seq']; }
function db_query($link, $query, $die_on_error = true) { //if ($_REQUEST["qlog"]) // error_log($_SESSION["uid"] . ":" . $_REQUEST["op"] . "/" . $_REQUEST["subop"] . // " $query\n", 3, "/tmp/ttrss-query.log"); if (DB_TYPE == "pgsql") { $result = pg_query($link, $query); if (!$result) { $query = htmlspecialchars($query); // just in case if ($die_on_error) { die("Query <i>{$query}</i> failed [{$result}]: " . pg_last_error($link)); } } return $result; } else { if (DB_TYPE == "mysql") { $result = mysql_query($query, $link); if (!$result) { $query = htmlspecialchars($query); if ($die_on_error) { die("Query <i>{$query}</i> failed: " . mysql_error($link)); } } return $result; } } }
private static function __query($sql) { if (!($res = pg_query(self::$__connection, $sql))) { throw new Exception(pg_last_error(self::$__connection)); } return $res; }
function search_db($netid) { global $dbfields; if (!preg_match("/\\A[a-z]{3}([0-9]*)\\Z/i", $netid)) { return array(); } init_db(); $query = "select * from users where netid='" . pg_escape_string($netid) . "'"; $result = pg_query($query); $present = pg_fetch_array($result, null, PGSQL_ASSOC); if ($present == null) { return array(); } $person = new Person($netid); pg_free_result($result); foreach ($dbfields as $f) { $query = "select * from " . $f . " where netid='" . pg_escape_string($netid) . "'"; $result = pg_query($query); while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { $value = $line[$f]; if ($line["ldap"] === "f") { $person->db_fields[$f][] = $value; } else { $person->ldap_fields[$f][] = $value; } } pg_free_result($result); } $person->refresh_db(); return array($person); }
function PQuery($query) { require "config.php"; global $connection; //error_log( $query ); //print $query."<br>"; $res = pg_query($connection, $query); if (!$res) { //print_r (debug_backtrace()); list(, $caller) = debug_backtrace(false); error_log($caller['function'] . ', ' . $caller['line'] . ": {$query}"); $result['count'] = 0; $result['rows'] = NULL; $result['error'] = pg_last_error($connection); return $result; } $result['count'] = pg_num_rows($res); $i = 0; $rowarr = array(); while ($row = pg_fetch_array($res, NULL, PGSQL_ASSOC)) { $rowarr[$i++] = $row; } pg_free_result($res); $result['rows'] = $rowarr; return $result; }