function exec_query($connection, $query) { $result = pg_Exec($connection, $query); if (!$result) { echo "Connection to database failed."; echo pg_ErrorMessage($connection); return 0; } return $result; }
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; }
public function execQuery($name, $query) { if ($GLOBALS['DB_DEBUG']) { echo $query . '<br>'; } if ($this->connection) { $this->freeResult($name); $this->result[$name] = pg_Exec($this->connection, $query); } $this->row = 0; return $this->result[$name]; }
function execute($sql, $db, $type = "mysql") { $start = $this->row * $this->numrowsperpage; if ($type == "mysql") { $result = mysql_query($sql, $db); $this->total_records = mysql_num_rows($result); $sql .= " LIMIT {$start}, {$this->numrowsperpage}"; $result = mysql_query($sql, $db); } elseif ($type == "pgsql") { $result = pg_Exec($db, $sql); $this->total_records = pg_NumRows($result); $sql .= " LIMIT {$this->numrowsperpage}, {$start}"; $result = pg_Exec($db, $sql); } return $result; }
function execute($sql, $db, $type = "mysql") { global $total_records, $row, $numtoshow; $numtoshow = $this->numrowsperpage; if (!isset($row)) { $row = 0; } $start = $row * $numtoshow; if ($type == "mysql") { $result = mysql_query($sql, $db); $total_records = mysql_num_rows($result); $sql .= " LIMIT {$start}, {$numtoshow}"; $result = mysql_query($sql, $db); } elseif ($type == "pgsql") { $result = pg_Exec($db, $sql); $total_records = pg_NumRows($result); $sql .= " LIMIT {$numtoshow}, {$start}"; $result = pg_Exec($db, $sql); } return $result; }
function fcdb_query_single_value($stmt) { global $fcdb_sel, $fcdb_conn; set_error_handler("fcdb_error_handler"); switch ($fcdb_sel) { case "PostgreSQL": $res = pg_Exec($fcdb_conn, $stmt); if (!$res) { build_fcdb_error("I cannot run a query: '{$stmt}'."); } $val = pg_Result($res, 0, 0); break; case "MySQL": $res = mysql_query($stmt, $fcdb_conn); if (!$res) { build_fcdb_error("I cannot run a query: '{$stmt}'."); } $val = mysql_result($res, 0, 0); break; } restore_error_handler(); return $val; }
function listOptionsLabel($dataset, $choixdef) { global $database; $result = pg_Exec($database, "SELECT * FROM " . $dataset); $Nbr = pg_NumRows($result); for ($i = 0; $i < $Nbr; $i++) { $tablo[$i] = pg_fetch_array($result, $i); } if ($Nbr > 2) { sort($tablo); } echo "<select name=liste_" . $dataset . ">\n"; for ($i = 0; $i < $Nbr; $i++) { list($cle, $label) = $tablo[$i]; if ($cle == $choixdef) { echo " <option selected>" . $cle . " = " . $label . "</option>\n"; } else { echo " <option>" . $cle . " = " . $label . "</option>\n"; } } echo "</select>\n"; return 1; }
function execute($sql, $db, $type = "mysql") { global $total_records, $row, $numtoshow; $numtoshow = $this->numrowsperpage; if (!isset($_GET['row'])) { $row = 0; } else { $row = $_GET['row']; } $start = $row * $numtoshow; if ($type == "mysql") { // echo " the sql statement is --".$sql."and Db is --".$db; $query_result = mysql_query($sql, $db); //$total_records = mysql_num_rows($query_result); $sql .= " LIMIT {$start}, {$numtoshow}"; $query_result = mysql_query($sql, $db); } elseif ($type == "pgsql") { $query_result = pg_Exec($db, $sql); $total_records = pg_NumRows($query_result); $sql .= " LIMIT {$numtoshow}, {$start}"; $query_result = pg_Exec($db, $sql); } return $query_result; }
function Sincronizar($db) { $rows = 0; // Number of rows $qid = 0; // Query result resource // See PostgreSQL developer manual (www.postgresql.org) for system table spec. // Get catalog data from system tables. $sql = 'SELECT * FROM migracion.f_sincronizacion()'; $qid = pg_Exec($db, $sql); // Check error if (!is_resource($qid)) { print 'Error en la Sincronizacion'; return null; } $rows = pg_NumRows($qid); // Store meta data for ($i = 0; $i < $rows; $i++) { $res = pg_Result($qid, $i, 0); // Field Name } echo 'Sincronizacion terminada (' . $res . ') - ' . date("m-d-Y H:i:s") . '<BR>'; return $res; }
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 GetLastInsertID($sTable) { @($res = pg_Exec($this->conn, "select currval('seq_{$sTable}')")); if ($res) { $Record = @pg_fetch_array($res, 0); @pg_FreeResult($res); return $Record[0]; } trigger_error("Error getting last insert ID for table {$sTable}! " . pg_ErrorMessage()); return -1; }
/** * 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; }
<!DOCTYPE html> <html> <head> <title>Conexión Exitosa</title> </head> <body> <font color="hotpink"><h1>Bienvenid@</h1></font> <?php /*Conexion con la base de datos*/ header("Content-type: text/html; charset=utf8"); $v_usuario = $_POST["username"]; $v_password = $_POST["password"]; $v_tabla = $_POST["tabla"]; $conexion = pg_connect("host=localhost port=5432 dbname=eventos user={$v_usuario} password={$v_password}"); echo "Datos de la tabla <b>{$v_tabla}</b>"; echo "<BR>"; echo "<BR>"; if ($v_tabla == "evento") { $sql = "select * from {$v_tabla}"; $resultado_set = pg_Exec($conexion, $sql); while ($row = pg_fetch_array($resultado_set)) { echo $row["cod_evento"] . ". <i>Nombre evento: </i>" . $row["nom_evento"] . " <i>Fecha: </i>" . $row["fecha_evento"] . " <i>Participantes: </i>" . $row["num_part_evento"] . " <i>Lugar: </i>" . $row["lug_evento"]; echo "<BR>"; } } pg_close($conexion); ?> </body> </html>
/** * Find the primary key of the last insertion on the current db connection * * @param string $table name of table the insert was performed on * @param string $field the autoincrement primary key of the table * @return integer the id, -1 if fails */ public function get_last_insert_id($table, $field = '') { switch ($GLOBALS['phpgw_info']['server']['db_type']) { case 'postgres': $params = explode('.', $this->adodb->pgVersion); if ($params[0] < 8 || $params[0] == 8 && $params[1] == 0) { $oid = pg_getlastoid($this->adodb->_resultid); if ($oid == -1) { return -1; } $result = @pg_Exec($this->adodb->_connectionID, "select {$field} from {$table} where oid={$oid}"); } else { $result = @pg_Exec($this->adodb->_connectionID, "select lastval()"); } if (!$result) { return -1; } $Record = @pg_fetch_array($result, 0); @pg_freeresult($result); if (!is_array($Record)) { return -1; } return $Record[0]; break; case 'mssql': /* MSSQL uses a query to retrieve the last * identity on the connection, so table and field are ignored here as well. */ if (!isset($table) || $table == '' || !isset($field) || $field == '') { return -1; } $result = @mssql_query("select @@identity", $this->adodb->_queryID); if (!$result) { return -1; } return mssql_result($result, 0, 0); break; default: return $this->adodb->Insert_ID($table, $field); } }
function query(&$db, $query = "") { // Constructor of the query object. // executes the query, notifies the db object of the query result to clean // up later if ($query != "") { if (!empty($this->result)) { $this->free(); // query not called as constructor therefore there may // be something to clean up. } $this->result = @pg_Exec($db->connect_id, $query); $db->addquery($this->result); $this->curr_row = 0; $this->query = $query; } }
function _query($sql, $inputarr) { $rez = pg_Exec($this->_connectionID, $sql); // check if no data returned, then no need to create real recordset if ($rez && pg_numfields($rez) <= 0) { $this->_resultid = $rez; return true; } return $rez; }
unset($_SESSION["acct_canon"]); } $_SESSION["acct_official"] = $_SESSION["acct_canon"] ? $_SESSION["acct_canon"] : $_SESSION["acct_username"]; if (!$addition) { $account = findAccount($_SESSION["acct_official"]); if ($account === false) { $id = createAccount(); addAccountUsername($id, $_SESSION["acct_official"], $_SESSION["acct_username"]); setAccountDetails($id, $sreg); if (isset($_COOKIE["pbguid"])) { setAccountGUID($id, $_COOKIE["pbguid"]); } setAccountAPIKey($id, makeApiKey()); $account = findAccount($_SESSION["acct_official"]); } else { pg_Exec($DB, "UPDATE accounts SET last_login=now() WHERE id=" . $account['id']); } $_SESSION["acct_id"] = $account['id']; $_SESSION["acct_sreg"] = $account; $_SESSION["kvp"] = findAccountKVP($account['id']); } else { pageHeader(_("new OpenID associated")); pageSidebar(); makeSection(_("your new OpenID has been associated")); print '<p>Thank you! Your new OpenID username has been associated with this account. You may now <a href="/settings.php">continue with more settings</a>.</p>'; pageFooter(); exit; } } else { print "Sorry, there was a general authentication failure.. <a href=\"/login.php\">Please try again.</a>"; exit;
function getValueFromDB2($tabl, $var, $qValues, $dbName) { $newConn = pg_connect('dbname=' . $dbName); $SQLstmt = "SELECT {$var} FROM {$tabl} WHERE " . where_list($qValues) . ";"; if (!$newConn) { echo "<!-- Couldn't connect to {$dbName} -->\n"; } //echo "<!-- $SQLstmt -->\n"; $result = pg_Exec($newConn, $SQLstmt); if (!$result) { echo "<p>Query failed to {$dbName} <br>"; echo $SQLstmt . "<br />\n"; echo pg_errormessage($newConn); $x = ''; } else { $x = pg_result($result, 0, $var); } pg_free_result($result); pg_close($newConn); return $x; }
</head> <body> <form> <center><td colspan='2' align='center'><h1><font color="red">Adicionar clientes</h1></font></td></center> <table align='center' width='225' cellspacing='2' cellpadding='2' border='0'> </form> <form> <left><td colspan='2' align='left'><h3>Cliente insertado</h3></td></left> <table align='left' width='100' cellspacing='2' cellpadding='2' border='0'> </form> <?php $v_cod_cliente = $_GET["cod_cliente"]; $v_nom_cliente = "'" . $_GET["nom_cliente"] . "'"; $conexion = pg_connect("host=192.168.6.55 port=5432 dbname=ventas user=postgres password=1234") or die('failed'); $sql = "INSERT INTO cliente(cod_cliente, nom_cliente) VALUES({$v_cod_cliente}, {$v_nom_cliente})"; $result = pg_Exec($conexion, $sql); $sql = "select cod_cliente, nom_cliente from cliente where cod_cliente = {$v_cod_cliente}"; $result = pg_Exec($conexion, $sql); while ($row = pg_fetch_array($result)) { echo $row["cod_cliente"] . "-->" . $row["nom_cliente"]; } echo "<br>"; ?> <form method='get' action='opciones.php'> <br> <input type='submit' value='Close'> </form> </body> </html>
$user_no = ""; $query = "SELECT user_no FROM usr WHERE username=LOWER('{$l}') and password=LOWER('{$p}')"; $result = pg_Exec($dbconn, $query); if (pg_NumRows($result) > 0) { $user_no = pg_Result($result, 0, "user_no"); } $requests = "<p><small>"; if ("{$user_no}" != "") { $query = "SELECT DISTINCT request.request_id, brief, last_activity, "; $query .= "lookup_desc AS status_desc, severity_code "; $query .= "FROM request, request_interested, lookup_code AS status "; $query .= "WHERE request.request_id=request_interested.request_id "; $query .= "AND status.source_table='request' "; $query .= "AND status.source_field='status_code' "; $query .= "AND status.lookup_code=request.last_status "; $query .= "AND request_interested.user_no={$user_no} "; $query .= "AND request.active "; $query .= "AND request.last_status~*'[AILNRQA]' "; $query .= "ORDER BY request.severity_code DESC LIMIT 20; "; $result = pg_Exec($dbconn, $query); if (!$result) { error_log("wrms wap/inc/getRequests.php query error: {$query}", 0); } for ($i = 0; $i < pg_NumRows($result); $i++) { $thisrequest = pg_Fetch_Object($result, $i); $requests .= "<a href=\"wrms.php?id={$thisrequest->request_id}\">" . tidy($thisrequest->brief) . "</a><br/>\n"; } } else { $requests .= "I'm sorry you must login first"; } $requests .= "</small></p>";
function Executar($sql, $conexao, $velocidade, $tipo) { global $nu_rel_maxlinhas; // variavel para o inicio das pesquisas $inicio_pesq = $this->pagina * $this->nu_rel_maxlinhas; if ($velocidade == "otimizada") { $total_sql = preg_replace("/SELECT (.*?) FROM /sei", "'SELECT COUNT(*) FROM '", $sql); } else { $total_sql = $sql; } // tipo da pesquisa if ($tipo == "mysql") { $resultado = mysql_query($total_sql); $this->total_reg = mysql_num_rows($resultado); // total de registros da pesquisa inteira $sql .= " LIMIT {$inicio_pesq}, {$this->nu_rel_maxlinhas}"; $resultado = mysql_query($sql); // pesquisa com limites por pagina } else { if ($tipo == "pgsql") { $resultado = pg_exec($conexao, $total_sql); if (pg_numrows($resultado) > 0) { // total de registros da pesquisa inteira $this->total_reg = pg_numrows($resultado); //pg_Result($resultado, 0, 0); } $sql .= " LIMIT {$this->nu_rel_maxlinhas}, {$inicio_pesq}"; $resultado = pg_Exec($conexao, $sql); // pesquisa com limites por pagina } } return $resultado; }
function _query($sql, $inputarr) { $this->_resultid = pg_Exec($this->_connectionID, $sql); return $this->_resultid; }
function nextid($seq_name) { $this->connect(); if ($this->lock($this->Seq_Table)) { /* get sequence number (locked) and increment */ $q = sprintf("select nextid from %s where seq_name = '%s' LIMIT 1", $this->Seq_Table, $seq_name); $id = @pg_Exec($this->Link_ID, $q); $res = @pg_Fetch_Array($id, 0); /* No current value, make one */ if (!is_array($res)) { $currentid = 0; $q = sprintf("insert into %s values('%s', %s)", $this->Seq_Table, $seq_name, $currentid); $id = @pg_Exec($this->Link_ID, $q); } else { $currentid = $res["nextid"]; } $nextid = $currentid + 1; $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'", $this->Seq_Table, $nextid, $seq_name); $id = @pg_Exec($this->Link_ID, $q); $this->unlock(); } else { $this->Errors->addError("Database error: Cannot lock " . $this->Seq_Table . " - has it been created?"); return 0; } return $nextid; }
/** * Free any resources allocated during the lifetime of the large object * handler object. * * @param int $lob handle to a lob created by the createLOB() function * @access private */ function _destroyResultLOB($lob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; if (isset($db->lobs[$lob])) { if (isset($db->lobs[$lob]['value'])) { @pg_loclose($db->lobs[$lob]['handle']); if (isset($db->lobs[$lob]['in_transaction'])) { @pg_Exec($db->connection, 'END'); } } $db->lobs[$lob] = ''; } }
function nextid($seq_name) { $this->connect(); if ($this->lock($this->Seq_Table)) { // get sequence number (locked) and increment $q = sprintf("\n SELECT \n nextid \n FROM \n %s \n WHERE \n seq_name = '%s'", $this->Seq_Table, $seq_name); $id = @pg_Exec($this->Link_ID, $q); $res = @pg_Fetch_Array($id, 0); // No current value, make one if (!is_array($res)) { $currentid = 0; $q = sprintf("\n INSERT INTO \n %s \n VALUES('%s', %s)", $this->Seq_Table, $seq_name, $currentid); $id = @pg_Exec($this->Link_ID, $q); } else { $currentid = $res["nextid"]; } $nextid = $currentid + 1; $q = sprintf("\n UPDATE \n %s \n SET \n nextid = '%s' \n WHERE \n seq_name = '%s'", $this->Seq_Table, $nextid, $seq_name); $id = @pg_Exec($this->Link_ID, $q); $this->unlock(); } else { $this->halt("cannot lock " . $this->Seq_Table . " - has it been created?"); return 0; } return $nextid; }
public function ejecuteQuery($p_query) { $this->total_querys++; $v_result = pg_Exec($this->conexion, $p_query); return $this->validateResult($v_result); }
$password = parse_url(getenv("DATABASE_URL"))["pass"]; $table = "track"; $connection = pg_connect("host={$host} port=5432 dbname={$database} user={$username} password={$password}"); $id = $_POST["id"]; $lat = $_POST["lat"]; $lng = $_POST["lng"]; $bat_sta = $_POST["bat_sta"]; $bat_lvl = $_POST["bat_lvl"]; if ($lat) { $sqlDel = "delete from track where id = {$id};"; pg_query($connection, $sqlDel); $sqlUpdate = "insert into track (id, latitude,longitude,battery_status,battery_level) \n\t\t\t\t\tvalues({$id} , '{$lat}', '{$lng}', '{$bat_sta}', '{$bat_lvl}');"; pg_query($connection, $sqlUpdate); echo $sqlUpdate; echo "<br>"; } $sql = "select * from {$table} order by id;"; $result = pg_Exec($connection, $sql); $i = pg_num_fields($result); /*for ($j = 0; $j < $i; $j++) { echo "column $j || "; $fieldname = pg_field_name($result, $j); echo "fieldname: $fieldname || "; echo "printed length: " . pg_field_prtlen($result, $fieldname) . " characters || "; echo "storage length: " . pg_field_size($result, $j) . " bytes || "; echo "field type: " . pg_field_type($result, $j) . " <br><br>"; }*/ while ($row = pg_fetch_array($result)) { echo "ID: " . $row["id"] . "<br>LAT: " . $row["latitude"] . "<br>LNG: " . $row["longitude"] . "<br>BAT-STATE: " . $row["battery_status"] . "<br>BAT-LEVEL: " . $row["battery_level"] . "<br>Y-VALUE: " . $row["y_value"]; echo "<br>===============<br>"; }
function RollbackTrans() { if ($this->transOff) { return true; } $this->transCnt -= 1; return @pg_Exec($this->_connectionID, "rollback"); }
function insert_id($col = "", $tbl = "", $qual = "") { global $FC_Link_ID; if (!empty($FC_Link_ID)) { $this->Link_ID = $FC_Link_ID; } $ires = pg_Exec($this->Link_ID, "select {$col} from {$tbl} where {$qual}"); if (!pg_Fetch_Row($ires, 0)) { return 0; } $iseq = pg_Result($ires, 0, "{$col}"); pg_FreeResult($ires); return $iseq; }