/** * @inheritdoc */ public function numRows() { if (!is_resource($this->result)) { return false; } return pg_num_rows($this->result); }
/** * \brief * delete from copyright where pfile_fk not in (select pfile_pk from pfile) * add foreign constraint on copyright pfile_fk if not exist * * \return 0 on success, 1 on failure **/ function Migrate_20_25($Verbose) { global $PG_CONN; $sql = "select count(*) from pg_class where relname='copyright';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); pg_free_result($result); if (1 > $row['count']) { return 0; // fresh install, even no copyright table } $sql = "delete from copyright where pfile_fk not in (select pfile_pk from pfile);"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); /** add foreign key CONSTRAINT on pfile_fk of copyrigyt table when not exist */ $sql = "SELECT conname from pg_constraint where conname= 'copyright_pfile_fk_fkey';"; $conresult = pg_query($PG_CONN, $sql); DBCheckResult($conresult, $sql, __FILE__, __LINE__); if (pg_num_rows($conresult) == 0) { $sql = "ALTER TABLE copyright ADD CONSTRAINT copyright_pfile_fk_fkey FOREIGN KEY (pfile_fk) REFERENCES pfile (pfile_pk) ON DELETE CASCADE; "; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); print "add contr\n"; } pg_free_result($conresult); return 0; }
public static function castResult($result, array $a, Stub $stub, $isNested) { $a['num rows'] = pg_num_rows($result); $a['status'] = pg_result_status($result); if (isset(self::$resultStatus[$a['status']])) { $a['status'] = new ConstStub(self::$resultStatus[$a['status']], $a['status']); } $a['command-completion tag'] = pg_result_status($result, PGSQL_STATUS_STRING); if (-1 === $a['num rows']) { foreach (self::$diagCodes as $k => $v) { $a['error'][$k] = pg_result_error_field($result, $v); } } $a['affected rows'] = pg_affected_rows($result); $a['last OID'] = pg_last_oid($result); $fields = pg_num_fields($result); for ($i = 0; $i < $fields; ++$i) { $field = array('name' => pg_field_name($result, $i), 'table' => sprintf('%s (OID: %s)', pg_field_table($result, $i), pg_field_table($result, $i, true)), 'type' => sprintf('%s (OID: %s)', pg_field_type($result, $i), pg_field_type_oid($result, $i)), 'nullable' => (bool) pg_field_is_null($result, $i), 'storage' => pg_field_size($result, $i) . ' bytes', 'display' => pg_field_prtlen($result, $i) . ' chars'); if (' (OID: )' === $field['table']) { $field['table'] = null; } if ('-1 bytes' === $field['storage']) { $field['storage'] = 'variable size'; } elseif ('1 bytes' === $field['storage']) { $field['storage'] = '1 byte'; } if ('1 chars' === $field['display']) { $field['display'] = '1 char'; } $a['fields'][] = new EnumStub($field); } return $a; }
function printUserLog() { //db connection $conn = pg_connect(HOST . " " . DBNAME . " " . USERNAME . " " . PASSWORD) or die('Could not connect: ' . pg_last_error()); //query the database $result = pg_prepare($conn, "getLog", "SELECT * FROM lab8.log\n\t\t\tWHERE username LIKE \$1") or die("getLog prepare fail: " . pg_last_error()); $result = pg_execute($conn, "getLog", array($_SESSION['user'])) or die("getLog execute fail: " . pg_last_error()); //Printing results in HTML echo "<br>There where <em>" . pg_num_rows($result) . "</em> rows returned<br><br>\n"; echo "<table class='tablestuff' border='1'>"; //account for added form row echo "<tr>"; //checking the number of fields return to populate header $numFields = pg_num_fields($result); //populating the header for ($i = 0; $i < $numFields; $i++) { $fieldName = pg_field_name($result, $i); echo "<th width=\"135\">" . $fieldName . "</th>\n"; } echo "</tr>"; //populating table with the results while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>{$col_value}</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; // Free resultset pg_free_result($result); //close connection pg_close($conn); }
function geoJsonEncode($query) { if (pg_num_rows($query) > 0) { $stationResult = "geojson_stations = { 'type': 'FeatureCollection','features': ["; $platformResult = "geojson_platforms = { 'type': 'FeatureCollection','features': ["; $stopResult = "geojson_stop_positions = { 'type': 'FeatureCollection','features': ["; while ($row = pg_fetch_assoc($query)) { if ($row['geom'] != "") { $feature = "\n\t\t\t\t\t{\n\t\t\t\t\t\t'type': 'Feature',\n\t\t\t\t\t\t'properties': {\n\t\t\t\t\t\t\t'id': '" . $row['id'] . "',\n\t\t\t\t\t\t\t'type': '" . $row['type'] . "',\n\t\t\t\t\t\t\t'name': '" . $row['name'] . "'\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'geometry': " . $row['geom'] . "\n\t\t\t\t\t},"; } switch ($row['type']) { case 'station': $stationResult .= $feature; break; case 'platform': $platformResult .= $feature; break; case 'stop': $stopResult .= $feature; break; } } $stationResult .= "]} \n"; $platformResult .= "]} \n"; $stopResult .= "]} \n"; return $stationResult . $platformResult . $stopResult; } }
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 sqlQuery($query) { if (!$query) { return false; } if (b1n_DEBUG) { echo '<pre style="text-align: left">QUERY: ' . $query . '</pre>'; } if (!$this->sqlIsConnected()) { user_error('DB NOT CONNECTED'); return false; } $result = pg_query($this->sqlGetLink(), $query); if (is_bool($result)) { return pg_affected_rows($result); } $num = pg_num_rows($result); if ($num > 0) { for ($i = 0; $i < $num; $i++) { $row[$i] = pg_fetch_array($result, $i, PGSQL_ASSOC); } return $row; } return true; }
function archive($_GET) { extract($_GET); $id += 0; db_conn('crm'); $Sl = "SELECT * FROM crms WHERE userid='" . USER_ID . "'"; $Ri = db_exec($Sl) or errDie("Unable to get data from system."); if (pg_num_rows($Ri) < 1) { return "Invalid."; } $crmdata = pg_fetch_array($Ri); $teams = explode("|", $crmdata['teams']); $Sl = "SELECT * FROM tokens WHERE id='{$id}'"; $Ri = db_exec($Sl) or errDie("Unable to get query."); if (pg_num_rows($Ri) < 1) { return "Invalid query."; } $tokendata = pg_fetch_array($Ri); if (!in_array($tokendata['teamid'], $teams)) { return "Declined."; } $Sl = "SELECT * FROM token_actions WHERE token='{$id}'"; $Ri = db_exec($Sl) or errDie("Unable to get actions from db."); while ($data = pg_fetch_array($Ri)) { $Sl = "INSERT INTO archived_actions (token,action,donedate,donetime,doneby,donebyid)\r\n\t\tVALUES ('{$id}','{$data['action']}','{$data['donedate']}','{$data['donetime']}','{$data['doneby']}','{$data['donebyid']}')"; $Ro = db_exec($Sl) or errDie("Unable to archive action."); } $Sl = "DELETE FROM token_actions WHERE token='{$id}'"; $Rl = db_exec($Sl) or errDie("Unable to delete actions."); $OUTPUT = "<script> window.opener.parent.mainframe.location.reload(); window.close(); </script>"; return $OUTPUT; }
public function count() { if ($this->_collection) { return pg_num_rows($this->_collection); } return null; }
function scan() { $invoice = array("invoice" => "Scan Invoice"); $barcode = flashRed($invoice); $barcode = $barcode["invoice"]; $sorder_num = decrypt_barcode($barcode); if (empty($sorder_num) || !is_numeric($sorder_num)) { $sorder_num = 0; } $prd_union = array(); for ($i = 1; $i <= 14; $i++) { $prd_union[] = "SELECT pslip_sordid FROM \"{$i}\".pinvoices WHERE pslip_sordid='{$sorder_num}'"; } $pinvoices_sql = implode(" UNION ", $prd_union); $sql = "SELECT pslip_sordid FROM cubit.invoices WHERE pslip_sordid='{$sorder_num}' UNION {$pinvoices_sql}"; $invoice_rslt = db_exec($sql) or errDie("Unable to check sales order id."); if (!pg_num_rows($invoice_rslt) || $sorder_num == 0) { return scan_error("Scanned invoice does not exist."); } $sql = "SELECT sordid FROM cubit.pslip_signed_index WHERE sordid='{$sorder_num}'"; $psi_rslt = db_exec($sql) or errDie("Unable to retrieve index."); if (pg_num_rows($psi_rslt) > 0) { scan_error("Signed invoice already uploaded"); } return enter($sorder_num); }
/** * @param resource from pg_query() or pg_get_result() * @param string SQL used to create this result * @param resource from pg_connect() or pg_pconnect() * @param boolean|string * @return void */ public function __construct($result, $sql, $link, $return_objects) { // PGSQL_COMMAND_OK <- SET client_encoding = 'utf8' // PGSQL_TUPLES_OK <- SELECT table_name FROM information_schema.tables // PGSQL_COMMAND_OK <- INSERT INTO pages (name) VALUES ('gone soon') // PGSQL_COMMAND_OK <- DELETE FROM pages WHERE id = 2 // PGSQL_COMMAND_OK <- UPDATE pb_users SET company_id = 1 // PGSQL_FATAL_ERROR <- SELECT FROM pages switch (pg_result_status($result)) { case PGSQL_EMPTY_QUERY: $this->total_rows = 0; break; case PGSQL_COMMAND_OK: $this->total_rows = pg_affected_rows($result); break; case PGSQL_TUPLES_OK: $this->total_rows = pg_num_rows($result); break; case PGSQL_COPY_OUT: case PGSQL_COPY_IN: Kohana_Log::add('debug', 'PostgreSQL COPY operations not supported'); break; case PGSQL_BAD_RESPONSE: case PGSQL_NONFATAL_ERROR: case PGSQL_FATAL_ERROR: throw new Database_Exception(':error [ :query ]', array(':error' => pg_result_error($result), ':query' => $sql)); } $this->link = $link; $this->result = $result; $this->return_objects = $return_objects; $this->sql = $sql; }
function show_comments_page($dbconn, $diary_login) { $nid = (int) $_GET['nid']; // Get Note $sql = "SELECT u.uid, n.* FROM " . TABLE_USERS . " AS u, " . TABLE_NOTES . " AS n WHERE u.login='******' AND n.uid=u.uid AND n.nid='" . $nid . "' LIMIT 1"; $result = pg_query($sql) or die(pg_last_error($dbconn)); if (pg_num_rows($result) == 0) { show_error_page($dbconn, $diary_login, "no such note!"); return; } else { $datanote = pg_fetch_object($result, NULL); pg_free_result($result); $sql = "SELECT u.uid, s.format_note, s.page_comments, s.format_comment FROM " . TABLE_SETTINGS . " AS s, " . TABLE_USERS . " AS u WHERE u.login='******' AND s.uid=u.uid LIMIT 1"; $result = pg_query($sql) or die(pg_last_error($dbconn)); $dataformat = pg_fetch_object($result, NULL); // Strip link to add comment and number of comments $dataformat->format_note = preg_replace('/(<a.* href="{hrefcomment}")(.+)(.*>)/', '', $dataformat->format_note); $dataformat->format_note = preg_replace('/(.?{commentscount}.?)/', '', $dataformat->format_note); $note = assign_vars($dataformat->format_note, array('{subject}' => $datanote->subject, '{contents}' => $datanote->contents, '{date}' => date("d-m-Y", $datanote->timestamp), '{time}' => date("H:i:s", $datanote->timestamp))); $comments = get_comments($dbconn, $diary_login, $dataformat->format_comment, $nid); $sql = "SELECT COUNT(c.*) AS commentscount FROM " . TABLE_USERS . " AS u, " . TABLE_COMMENTS . " AS c WHERE c.nid='" . $nid . "' AND c.uid=u.uid AND u.login='******'"; $result = pg_query($sql) or die(pg_last_error($dbconn)); $datacount = pg_fetch_object($result, NULL); pg_free_result($result); $commentscount = (int) $datacount->commentscount; echo assign_vars($dataformat->page_comments, array('{login}' => $diary_login, '{note}' => $note, '{comments}' => $comments, '{commentscount}' => $commentscount, '{hrefcommentadd}' => 'http://' . $_SERVER['SERVER_NAME'] . '/' . PAGE_COMMENTS . '&nid=' . $nid . '&action=add')); } }
public function testUniqueCheck($username, $email) { //Get info from the array $final_username = $username; $final_email = $email; //Connect to the db $db = $this->connectProd(); //Check for username and email address $query_user_check = "SELECT username FROM tb_users WHERE username = '******'"; $query_email_check = "SELECT email FROM tb_users WHERE email = '" . $final_email . "'"; pg_send_query($db, $query_user_check) or die('Query failed: ' . pg_last_error()); $username_check_result = pg_get_result($db); $username_check_result_rows = pg_num_rows($username_check_result); pg_close($db); if ($username_check_result_rows == 0) { //Set flag if no user found $user_check = 'pass'; } else { $user_check = 'fail'; } if ($email_check_result_rows == 0) { //Set flag if no email is found $email_check = 'pass'; } else { $email_check = 'fail'; } if ($email_check == 'pass' && $user_check == 'pass') { $check_result = 'pass'; return $check_result; } else { $check_result = 'fail'; return $check_result; } }
function comprobar_nick_modificar(&$error, $nick, $id) { $res = pg_query_params("select * from usuarios where nick = \$1 and id != \$2", array($nick, $id)); if (pg_num_rows($res) > 0) { $error[] = "nick cogido. Escoja otro."; } }
function enter_err($_POST, $err = "") { global $_POST; extract($_POST); if (!isset($username)) { $username = ""; $name = ""; $email = ""; $cell = ""; } // $S1 = "SELECT * FROM usradd ORDER BY username "; $Ri = db_exec($S1) or errDie("Unable to get data."); if (pg_num_rows($Ri) < 1) { return "no user selected."; } // Set up table to display in //$cons="<table>"; $cons = "\r\n\t\t<h3>User Details</h3>\r\n\t\t<td align=center>\r\n\t\t<table border=1 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=300 class='bg-odd' >\r\n\t\t<tr><th>Name</th><th colspan=2>Options</th></tr>"; while ($data = pg_fetch_array($Ri)) { $cons .= "<tr><td class='bg-odd'>{$data['username']}</td><td><a\r\n\t\t href='usredit.php?id={$data['id']}'>Edit</a></td><td><a \r\n\t href='usrem.php?id={$data['id']}'>Remove</td></tr>"; } $Cons = "<select size=1 name=Con>\r\n <option value='No'>No</option>\r\n <option selected value='Yes'>Yes</option>\r\n </select>"; $Grps = "<select size=1 name=Con>\r\n <option value='Grp1'>Group test</option>\r\n <option selected value='Grp2'>Gruop test2</option>\r\n </select>"; $get_data = "\r\n\t <h3>New User Details</h3>\r\n\t <table cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\r\n\t <form action='" . SELF . "' method='post'>\r\n\t <tr><td>{$err}<br></td></tr>\r\n\t <input type=hidden name=key value='confirm'>\r\n\t <tr class='bg-odd'><td>Username</td><td><input type=text size=20 name=username value='{$username}'> must not contain spaces</td></tr>\r\n\t <tr class='bg-even'><td>Password</td><td><input type=password size=20 name=password></td></tr>\r\n <tr class='bg-odd'><td>Confirm password</td><td><input type=password size=20 name=password2></td></tr>\r\n\t <tr class='bg-even'><td>Name</td><td><input type=text size=20 name=name value='{$name}'></td></tr>\r\n\t <tr class='bg-odd'><td>Email</td><td><input type=text size=20 name=email value='{$email}'></td></tr>\r\n\t <tr class='bg-even'><td>Cellphone</td><td><input type=text size=20 name=cell value='{$cell}'></td></tr>\r\n\t <tr class='bg-odd'><td>Additional</td><td>Email Notification<input type=checkbox name=notify></td></tr>\r\n\t <tr class='bg-even'><td>Private</td><td align=center>{$Cons}</td></tr>\r\n\t <tr class='bg-odd'><td>Initial Group</td><td align=center>{$Grps}</td></tr>\r\n\t<tr><td colspan=2 align=right><input type=submit value='Confirm »'></td></tr>\r\n\t</form>\r\n\t</table>{$cons}"; return $get_data; }
function update() { extract($_REQUEST); pglib_transaction("BEGIN"); if (isset($rem)) { foreach ($rem as $type_id => $accid) { $sql = "DELETE FROM cubit.ratio_account_owners\n\t\t\t\t\tWHERE type_id='{$type_id}' AND accid='{$accid}'"; db_exec($sql) or errDie("Unable to remove entries."); } } if (isset($account)) { foreach ($account as $type_id => $accid) { if ($accid) { $sql = "SELECT id FROM cubit.ratio_account_owners\n\t\t\t\t\t\tWHERE type_id='{$type_id}' AND accid='{$accid}'"; $own_rslt = db_exec($sql) or errDie("Unable to retrieve owners."); if (!pg_num_rows($own_rslt)) { $sql = "INSERT INTO cubit.ratio_account_owners (type_id, accid)\n\t\t\t\t\t\t\tVALUES ('{$type_id}', '{$accid}')"; db_exec($sql) or errDie("Unable to add new entries."); } } } } pglib_transaction("COMMIT"); return display(); }
/** * mengambil record dari sebuah tabel dalam bentuk array * @param sqlString ini sql string * @param offset * */ public function getRecord($sqlString, $offset = 1) { // echo $sqlString; if (pg_num_rows($result = $this->query($sqlString)) >= 1) { $ft = $this->getFieldTable("field"); // print_r($ft); $countFieldTable = count($ft); $counter = 1; while ($row = pg_fetch_array($result)) { // echo $row . "<br>"; $tempRecord['no'] = $offset; for ($i = 0; $i < $countFieldTable; $i++) { $tempRecord[$ft[$i]] = trim($row[$ft[$i]]); } $ListRecord[$counter] = $tempRecord; $counter++; $offset++; } // print_r($ListRecord); $this->ListRecord = $ListRecord; } else { $this->ListRecord = array(); } return $this->ListRecord; }
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 construirListado($resultado) { if ($resultado && pg_num_rows($resultado) > 0) { $cadenaHTML = "<table border ='1'>"; $cadenaHTML .= "<tr>"; $cadenaHTML .= "<th>Codigo</th>"; $cadenaHTML .= "<th>Nombre</th>"; $cadenaHTML .= "<th>Apellido</th>"; $cadenaHTML .= "<th>Cedula</th>"; $cadenaHTML .= "<th>Edad</th>"; $cadenaHTML .= "<th>Semestre</th>"; $cadenaHTML .= "</tr>"; for ($cont = 0; $cont < pg_numrows($resultado); $cont++) { $cadenaHTML .= "<tr>"; $cadenaHTML .= "<td>" . pg_result($resultado, $cont, 0) . "</td>"; $cadenaHTML .= "<td>" . pg_result($resultado, $cont, 1) . "</td>"; $cadenaHTML .= "<td>" . pg_result($resultado, $cont, 2) . "</td>"; $cadenaHTML .= "<td>" . pg_result($resultado, $cont, 3) . "</td>"; $cadenaHTML .= "<td>" . pg_result($resultado, $cont, 4) . "</td>"; $cadenaHTML .= "<td>" . pg_result($resultado, $cont, 5) . "</td>"; $cadenaHTML .= "</tr>"; } $cadenaHTML .= "</table>"; } else { $cadenaHTML = "<b>No hay Registros en la Base de datos</b>"; } header('location:../index.php?page=estudiantes&&info_list=' . $cadenaHTML); }
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 archive($_GET) { extract($_GET); $id += 0; db_conn('crm'); $Sl = "SELECT * FROM crms WHERE userid='" . USER_ID . "'"; $Ri = db_exec($Sl) or errDie("Unable to get data from system."); if (pg_num_rows($Ri) < 1) { return "Invalid."; } $crmdata = pg_fetch_array($Ri); $teams = explode("|", $crmdata['teams']); $Sl = "SELECT * FROM tokens WHERE id='{$id}'"; $Ri = db_exec($Sl) or errDie("Unable to get query."); if (pg_num_rows($Ri) < 1) { return "Invalid query."; } $tokendata = pg_fetch_array($Ri); if (!in_array($tokendata['teamid'], $teams)) { return "Declined."; } $i = 0; $pactions = "<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='100%'>\r\n\t<tr><td colspan=3 align=center><h4>Archived Actions</h4></td></tr>\r\n\t<tr><th>Date</th><th>Action</th><th>Done By</th></tr>"; $Sl = "SELECT donedate,donetime,action,doneby FROM archived_actions WHERE token='{$id}' ORDER BY id DESC"; $Ry = db_exec($Sl) or errDie("Unable to get query actions from system."); while ($pdata = pg_fetch_array($Ry)) { $i++; $pactions .= "<tr class='" . bg_class() . "'><td>{$pdata['donedate']}, " . substr($pdata['donetime'], 0, 5) . "</td><td>{$pdata['action']}</td><td>{$pdata['doneby']}</td></tr>"; } $pactions .= "</table>"; return $pactions; }
function write_data($_POST) { # get vars foreach ($_POST as $key => $value) { ${$key} = $value; } db_conn('cubit'); if (!pglib_transaction("BEGIN")) { return "<li class=err>Unable to edit group(TB)</li>"; } $Sl = "SELECT * FROM grpadd WHERE id='{$id}'"; $Ri = db_exec($Sl) or errDie("Unable to get group details."); if (pg_num_rows($Ri) < 1) { return "Invalid group."; } $cdata = pg_fetch_array($Ri); # write to db $S1 = "UPDATE grpadd SET grpname='{$grpname}',unit='{$unit}' WHERE id = '{$id}'"; $Ri = db_exec($S1) or errDie("Unable to access database."); $Data = pg_fetch_array($Ri); if (!pglib_transaction("COMMIT")) { return "<li class=err>Unable to edit group. (TC)</li>"; } $write_data = "<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='50%'>\r\n\t<tr><th>Group Added</th></tr>\r\n\t<tr class=datacell><td>{$grpname} has been added to Cubit.</td></tr>\r\n\t</table>\r\n\t<p>\r\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\r\n\t<tr><th>Quick Links</th></tr>\r\n <tr class='bg-odd'><td><a href='docman-index.php'>Document Management</a></td></tr>\r\n\t</table>"; return $write_data; }
public function filasAfectadas($resultado) { if (!is_resource($resultado)) { return false; } return pg_num_rows($resultado); }
function confirm($_GET) { extract($_GET); $id += 0; db_conn('crm'); $Sl = "SELECT * FROM teams WHERE id='{$id}'"; $Ry = db_exec($Sl) or errDie("Unable to get team info."); if (pg_numrows($Ry) < 1) { return "Invalid team."; } $teamdata = pg_fetch_array($Ry); $Sl = "SELECT * FROM crms WHERE div='" . USER_DIV . "'"; $Ry = db_exec($Sl) or errDie("Unable to get data."); while ($cdata = pg_fetch_array($Ry)) { $teams = explode("|", $cdata['teams']); if (in_array($id, $teams)) { return "You Cannot remove this team, {$cdata['name']} is still allocated to it."; } } $Sl = "SELECT * FROM crms WHERE div='" . USER_DIV . "' AND teamid='{$id}'"; $Ry = db_exec($Sl) or errDie("Unable to get data."); if (pg_num_rows($Ry) > 0) { $cdata = pg_fetch_array($Ry); return "You Cannot remove this team, {$cdata['name']} still has it set as its default."; } $out = "\r\n\t\t\t\t<h3>Remove Cubit Team</h3>\r\n\t\t\t\t<form action='" . SELF . "' method='POST'>\r\n\t\t\t\t\t<input type='hidden' name='key' value='remove'>\r\n\t\t\t\t\t<input type='hidden' name='id' value='{$id}'>\r\n\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<th colspan='2'>Team Details</th>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Team Name</td>\r\n\t\t\t\t\t\t<td>{$teamdata['name']}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Description</td>\r\n\t\t\t\t\t\t<td>{$teamdata['des']}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td colspan='2' align='right'><input type='submit' value='Remove »'></td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</form>\r\n\t\t\t\t</table>"; return $out; }
function get_db_variables() { $sql_str = "SELECT " . "var_name, " . "var_value " . "FROM " . "portal_config_variables "; $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; } $n_rows = pg_num_rows($result); $vars = array(); for ($i = 0; $i < $n_rows; $i++) { $vars[pg_fetch_result($result, $i, 'var_name')] = pg_fetch_result($result, $i, 'var_value'); } $this->dbconn->disconnect(); // set member variables from name/value pairs $this->upload_path = $vars["upload_path"]; $this->mapfile_path = $vars["mapfile_path"]; $this->layer_config_path = $vars["layer_config_path"]; $this->mapservice_config_path = $vars["mapservice_config_path"]; $this->mapservice_name = $vars["mapservice_name"]; $this->map_agent = $vars["map_agent"]; $this->map_agent_launch_url = $vars["map_agent_launch_url"]; $this->output_dir = $vars["output_dir"]; $this->ogr2ogr_path = $vars["ogr2ogr_path"]; $this->confirmation_email_template = $vars["confirmation_email_template"]; return true; }
function numero_de_filas($result) { if (!is_resource($result)) { return false; } return pg_num_rows($result); }
function enter($errors = "") { extract($_REQUEST); $fields = array(); $fields["page_option"] = "Add"; $fields["id"] = 0; $fields["user_id"] = 0; $fields["description"] = ""; extract($fields, EXTR_SKIP); if (strtolower($page_option) == "edit") { $sql = "SELECT * FROM project.people WHERE id='{$id}'"; $edit_rslt = db_exec($sql) or errDie("Unable to retrieve people."); if (pg_num_rows($edit_rslt)) { extract(pg_fetch_array($edit_rslt)); } else { $page_option = "Add"; } } // Cubit users dropdown --------------------------------------------------- $sql = "SELECT * FROM cubit.users"; $user_rslt = db_exec($sql) or errDie("Unable to retrieve cubit users."); $user_sel = "<select name='user_id'>"; while ($user_data = pg_fetch_array($user_rslt)) { if ($user_id == $user_data["userid"]) { $sel = "selected"; } else { $sel = ""; } $user_sel .= "<option value='{$user_data['userid']}' {$sel}>\n\t\t\t{$user_data['username']}\n\t\t</option>"; } $user_sel .= "</select>"; $OUTPUT = "<h3>{$page_option} Person</h3>\n\t<form method='post' action='" . SELF . "'>\n\t<input type='hidden' name='key' value='confirm' />\n\t<input type='hidden' name='page_option' value='{$page_option}' />\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<td colspan='2'>{$errors}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan='2'>Person Details</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Cubit User</td>\n\t\t\t<td>{$user_sel}</td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Person Description</td>\n\t\t\t<td><input type='text' name='description' value='{$description}' /></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan='2' align='right'>\n\t\t\t\t<input type='submit' value='Confirm »' />\n\t\t\t</td>\n\t\t</tr>\n\t</table>\n\t</form>"; return $OUTPUT; }
/** * getTableStructure * */ function getTableStructure() { $link = $this->connect(); $this->tableStructure = array(); $campos = pg_query("SELECT column_name AS Field , udt_name AS Type , is_nullable AS null ,ordinal_position AS Key, column_default AS default FROM information_schema.columns WHERE table_name = '" . $this->tableName . "'"); // $campos = mysql_query("SHOW COLUMNS FROM " . $this->tableName); /* while ($linea = pg_fetch_array($campos)){ * echo $linea['column_name']; * }*die(); */ if ($campos) { //if (mysql_num_rows($campos) > 0) { if (pg_num_rows($campos) > 0) { //while ($row = mysql_fetch_assoc($campos)) { while ($row = pg_fetch_assoc($campos)) { //echo ('entro aqui');die(); $campo = $row['field']; //if ($row['Key'] == 'PRI') { if ($row['key'] == 1) { $this->primaryKey = $campo; $this->tableStructure[$campo] = '1'; //print_r($this->primaryKey);print_r($this->tableStructure);die(); } else { $this->tableStructure[$campo] = '0'; } } } } $this->disconnect($link); }
function auth($user, $pass, $args) { $host = access_query("authpgsqlhost", 0); $dbuser = access_query("authpgsqluser", 0); $dbpass = access_query("authpgsqlpass", 0); $dbname = access_query("authpgsqldb", 0); $tbname = access_query("authpgsqltable", 0); $lname = access_query("authpgsqllogincolumn", 0); $pname = access_query("authpgsqlpasscolumn", 0); $ps = trim($pass); switch (strtolower(access_query("authpgsqlpasstype", 0))) { case "md5": $pstr = md5($ps); break; case "plain": default: $pstr = $ps; } if (is_callable("pg_connect")) { if ($cid = @pg_connect("host={$host} user={$dbuser} password={$dbpass} dbname={$dbname}")) { if ($q = @pg_query($cid, "SELECT * FROM {$tbname} WHERE {$lname} = '{$user}' AND {$pname} = '{$pstr}'")) { $r = pg_num_rows($q); pg_free_result($q); $auth = $r > 0; } else { techo("WARN: mod_auth_pgsql could not fetch '{$lname}' and '{$pname}' from table '{$tbname}'", NW_EL_WARNING); } } else { techo("WARN: mod_auth_pgsql could not connect to database '{$dbname}@{$host}'", NW_EL_WARNING); } } else { techo("WARN: postgresql extension not built in your PHP binary", NW_EL_WARNING); } return $auth; }
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; }