public function executeQuery($sql) { //prepare query $sql = $this->prepareQuery($sql); $parts = explode(" ", trim($sql)); $type = strtolower($parts[0]); $hash = md5($sql); $this->lastHash = $hash; if ($type == "select") { if (isset($this->results[$hash])) { if (is_resource($this->results[$hash])) { return $this->results[$hash]; } } } else { if ("update" == $type || "delete" == $type) { $this->results = array(); //clear the result cache } } $query = pg_query($this->connection, $sql); if (!$query) { echo pg_errormessage($this->connection); } $this->results[$hash] = $query; return $this->results[$hash]; }
function get_provider_data($provider_id) { $qry = pg_query_params("select sp_home_page, contactemail from techmatcher.serviceprovider where serviceprovider_id=\$1", array($provider_id)) or die(pg_errormessage()); $result = pg_fetch_assoc($qry); $_SESSION['provider']['contactemail'] = $result['contactemail']; return $result["sp_home_page"]; }
/** * Удалить код активации * * @param integer $fid ID Пользователя, у которого удаляем код активации * @return string Сообщение об ошибке */ function Delete($fid) { global $DB; $sql = "DELETE FROM activate_mail WHERE user_id = ?"; $DB->query($sql, $fid); return pg_errormessage(); }
public function query($string = '') { if ($string != '') { $this->query = $this->escape($string); } else { $this->query = $this->select . $this->insert . $this->update . $this->delete . $this->create . $this->from . $this->join . $this->where . $this->group . $this->order . $this->limit; } $this->insert = " RETURNING id"; $this->result = pg_exec($this->connection, $this->query); $this->inserted_id = $this->result; $this->error = pg_errormessage($this->connection); $this->affected_rows = pg_affected_rows($this->result); $this->select = ''; $this->insert = ''; $this->update = ''; $this->delete = ''; $this->create = ''; $this->from = ''; $this->join = ''; $this->where = ''; $this->group = ''; $this->order = ''; $this->limit = ''; return $this; }
function my_handler($sql_insert) { global $table, $link, $new_name; $sql_insert = ereg_replace($table, $new_name, $sql_insert); $result = pg_exec($link, pre_query($sql_insert)) or pg_die(pg_errormessage($link), $sql_insert, __FILE__, __LINE__); $sql_query = $sql_insert; }
/** * Изменить параметр "видимости" анонима на противоположный * * @param integer $aid идентификатор анонима * @return char сообщение об ошибке */ function ChVisible($aid) { global $DB; $sql = "UPDATE anonymous SET visible = NOT visible::bool WHERE id = ?"; $DB->squery($sql, $aid); $error = pg_errormessage(); return $error; }
function get_address_by_serviceid($serviceprovider_id) { $result = pg_query_params("SELECT address_id FROM techmatcher.serviceprovidertoaddress WHERE serviceprovider_id=\$1 AND address_deleted=\$2", array($serviceprovider_id, "FALSE")) or die(pg_errormessage()); $names = array(); while ($name = pg_fetch_assoc($result)) { $names[] = $name; } return $names; }
public function ejecutarConsulta($sql) { $resultado = pg_query($this->conexion, $sql) or die("La consulta fallo1: " . pg_last_error($this->conexion)); if (!isset($resultado)) { echo "La consulta fallo2: " . pg_errormessage(); exit; } return $resultado; }
function set_privilege($sql_set_privilege) { global $link; if (!($res = @pg_exec($link, $sql_set_privilege))) { pg_die(pg_errormessage($link), $sql_set_privilege, __FILE__, __LINE__); } else { echo "<p>{$sql_set_privilege}</p>\n"; } }
function get_staff_for_provider($serviceprovider_id) { $result = pg_query_params("SELECT spstaff_id FROM techmatcher.serviceprovidershavestaff WHERE serviceprovider_id = \$1", array($serviceprovider_id)) or die(pg_errormessage()); $names = array(); while ($name = pg_fetch_assoc($result)) { $names[] = $name; } return $names; }
/** * A method to set the client charset * * @param string $charset * @return mixed True on success, PEAR_Error otherwise */ function setClientCharset($charset) { if (!empty($charset) && $this->oDbh) { $pg = $this->oDbh->getConnection(); if (@pg_set_client_encoding($pg, $charset) == -1) { return new PEAR_Error(pg_errormessage($pg)); } } return true; }
function connect() { $this->link = pg_connect("host='" . $this->hostname . "' port='" . $this->port . "' dbname='" . $this->db . "' user='******' password='******'"); if (!$this->link) { $this->error = pg_errormessage($this->db); return false; } $this->exeq("set search_path to '" . $this->schema . "'"); return true; }
function getSP_Rated() { $qry = "SELECT * FROM techmatcher.ratingevents where ratingtotal>0;"; $result = pg_query_params($qry, array()) or die(pg_errormessage()); if (pg_num_rows($result) > 0) { return $result; } else { return false; } }
function FetchByMaster($MasterName) { $sql = "\nSELECT id AS slave_port_id,\n name AS slave_port_name,\n category_id AS slave_category_id,\n category AS slave_category_name\n FROM ports_active\n WHERE master_port = '" . pg_escape_string($MasterName) . "'\nORDER BY slave_category_name, slave_port_name"; #echo "sql = <pre>$sql</pre>"; $this->LocalResult = pg_exec($this->dbh, $sql); if (!$this->LocalResult) { echo pg_errormessage() . " {$sql}"; } $numrows = pg_numrows($this->LocalResult); return $numrows; }
function Insert() { # delete the ignore entry for this commit/port combination $sql = "\nINSERT INTO commit_log_ports_ignore (commit_log_id, port_id, reason)\n values ({$this->commit_log_id}, {$this->port_id}, '" . pg_escape_string($this->reason) . "')"; echo "\$sql='<pre>{$sql}</pre><br>\n"; $this->result = pg_exec($this->dbh, $sql); if (!$this->result) { echo pg_errormessage() . " {$sql}"; } $numrows = pg_affected_rows($this->result); return $numrows; }
function next_record() { $this->Record = @pg_fetch_array($this->Query_ID, $this->Row); $this->Row += 1; $this->Error = pg_errormessage(); $stat = is_array($this->Record); if (!$stat) { pg_freeresult($this->Query_ID); $this->Query_ID = 0; } return $this->Record; }
function obtenerMaximo($tabla, $campo, $b) { $query = "SELECT max({$campo}) as maximo\r\n\t FROM {$tabla}"; if ($result = pg_query($b, $query)) { while ($row = pg_fetch_array($result)) { $maximo = $row["maximo"]; } } else { $maximo = pg_errormessage($this->dbOrigen); } pg_free_result($result); return $maximo; }
function freshports_WatchListCountDefault($db, $UserID) { $sql = "select WatchListCountDefault({$UserID}) as count"; # echo $sql; $result = pg_exec($db, $sql); if (!$result) { echo "error " . pg_errormessage(); exit; } $myrow = pg_fetch_array($result, 0); # echo $myrow["count"]; return $myrow["count"]; }
function FetchInitialise($port_id) { # get ready to fetch all the commit_log_ports_vuxml for this port # return the number of commits found $sql = "\nselect CLPV.id,\n CLPV.commit_log_id, \n CLPV.port_id,\n CLPV.vuxml_id,\n vuxml.vid\n from commit_log_ports_vuxml CLPV, vuxml\n where CLPV.port_id = {$port_id}\n and CLPV.vuxml_id = vuxml.id\n order by CLPV.commit_log_id "; # echo "\$sql='<pre>$sql</pre><br>\n"; $this->result = pg_exec($this->dbh, $sql); if (!$this->result) { echo pg_errormessage() . " {$sql}"; } $numrows = pg_numrows($this->result); return $numrows; }
public function storeEvent(EventEnvelope $event, $seriesName) { $seriesNumber = $this->createSeriesIfNeeded($seriesName); $this->ensureConnection(); $prepareRes = pg_prepare($this->connection, 'storeEvent', 'insert into ' . $this->config->get('postgres.prefix', true) . 'events values (now(), $1, $2, $3)'); if ($prepareRes === false) { throw new \RuntimeException(pg_errormessage($this->connection)); } $res = pg_execute($this->connection, 'storeEvent', array($seriesNumber, $event->value, json_encode($event->payload))); if ($res === false) { throw new \RuntimeException(pg_errormessage($this->connection)); } return true; }
/** * Получение дополнительной информации о сообщении * * @param integer $msg_id ИД сообщения * @param string $error Возвращает сообщение об ошибке * @return array $ret Информация выборки */ function GetMsgInfo($msg_id, &$error) { $curname = get_class($this); global $DB; $sql = "SELECT * FROM {$curname} LEFT JOIN users ON users.uid={$curname}.fromuser_id WHERE id = ?"; $res = $DB->query($sql, $msg_id); $error = pg_errormessage(); if (!$error && pg_num_rows($res) > 0) { $ret = pg_fetch_assoc($res); //Определить $kind $ret['kind'] = $kind; } return $ret; }
/** * Performs an SQL query. * * @param string $query * @param mixed $limit * @param boolean $warnOnFailure * @access public */ function query($query, $limit = false, $warnOnFailure = true) { if ($limit != false) { $query .= ' LIMIT ' . $limit; } if ($this->config['debug_level'] > 1) { $this->debugQuery($query); } @pg_freeresult($this->result); $this->result = @pg_exec($this->connection, $query); if (!$this->result && $warnOnFailure) { phpOpenTracker::handleError(@pg_errormessage($this->connection), E_USER_ERROR); } }
function FetchAll() { # fetch all unrefreshed ports $Debug = 1; $sql = "\nselect ports.id as port_id,\r\n element.name as port_name,\n categories.id as category_id,\r\n categories.name as category_name,\r\n commit_log_ports.commit_log_id,\r\n commit_log_ports_ignore.date_ignored,\r\n commit_log_ports_ignore.reason,\n commit_log.message_id\r\n from ports, categories, element, commit_log, commit_log_ports LEFT OUTER JOIN commit_log_ports_ignore\r\n ON (commit_log_ports.commit_log_id = commit_log_ports_ignore.commit_log_id AND\r\n commit_log_ports.port_id = commit_log_ports_ignore.port_id)\r\n where ports.category_id = categories.id\r\n and ports.element_id = element.id\r\n and commit_log_ports.port_id = ports.id\r\n and commit_log_ports.needs_refresh <> 0\r\n and element.status = 'A'\n and commit_log_ports.commit_log_id = commit_log.id\r\norder by category_name, port_name"; # if ($Debug) echo "<pre>$sql</pre>"; $this->LocalResult = pg_exec($this->dbh, $sql); if ($this->LocalResult) { $numrows = pg_numrows($this->LocalResult); } else { echo 'pg_exec failed: <pre>' . $sql . '</pre> : ' . pg_errormessage(); } return $numrows; }
function __construct($connection_string) { //echo "Opening Connection\n"; $this->pg_connection = pg_connect($connection_string); if (!$this->pg_connection) { throw new DatabaseException('Connection Error'); } if (PGSQL_CONNECTION_OK != pg_connection_status($this->pg_connection)) { throw new DatabaseException(pg_errormessage($this->pg_connection)); } // Timezone // Serialisation // Log? }
function FetchInitialise($element_id) { # get ready to fetch all the commit_log_elements for this element # return the number of commits found $sql = "\nselect commit_log_elements.element_id, \n message_id,\n to_char(commit_date - SystemTimeAdjust(), 'DD Mon YYYY HH24:MI:SS') as commit_date,\n commit_log.description,\n committer,\n encoding_losses,\n revision_name\n from commit_log, commit_log_elements\n where commit_log.id = commit_log_elements.commit_log_id\n and commit_log_elements.element_id = {$element_id}\n order by commit_log.commit_date desc "; if ($Debug) { echo "\$sql='<pre>{$sql}</pre><br>\n"; } $this->result = pg_exec($this->dbh, $sql); if (!$this->result) { echo pg_errormessage() . " {$sql}"; } $numrows = pg_numrows($this->result); return $numrows; }
function FetchInitialise($WatchListID) { # fetch all rows in ports_moved with To_port_id = $PortID $Debug = 0; $sql = "SELECT * from WatchListDeletedPorts({$WatchListID})"; if ($Debug) { echo "<pre>{$sql}</pre>"; } $this->LocalResult = pg_exec($this->dbh, $sql); if ($this->LocalResult) { $numrows = pg_numrows($this->LocalResult); } else { echo 'pg_exec failed: <pre>' . $sql . '</pre> : ' . pg_errormessage(); } return $numrows; }
function StagingAlreadyInUse($UserID, $dbh) { $Result = 1; // yes, already in progress. $sql = "select WatchListStagingExists({$UserID})"; $result = pg_exec($dbh, $sql); if ($result && pg_numrows($result)) { $row = pg_fetch_array($result, 0); if ($row[0] == 0) { $Result = 0; } } else { echo pg_errormessage() . " sql = {$sql}"; } return $Result; }
function DBSize($db) { $sql = "select pg_database_size(current_database())"; $result = pg_exec($db, $sql); if ($result) { $numrows = pg_numrows($result); if ($numrows) { $myrow = pg_fetch_array($result, 0); $Value = $myrow[0]; } else { $Value = 'numrows = ' . $numrows . ' ' . $sql; } } else { $Value = pg_errormessage(); } return $Value; }
function tab_result($pgx, $quest) { $resultat = pg_exec($pgx, $quest); if (!$resultat) { pg_errormessage(); echo $quest; } $num = pg_numrows($resultat); // if ($num>0){ for ($i = 0; $i < $num; $i++) { $arr[$i] = pg_fetch_array($resultat, $i); } // }else{ // $arr='0'; // } return $arr; }
function insert() { if (isset($_POST['submit'])) { $connStr = "host=127.0.0.1 port=5432 dbname=test user=postgres password=jupiter"; //simple check $conn = pg_connect($connStr); $name = $_POST['name']; $last_name = $_POST['last_name']; $query = "insert into student(name,last_name) values('{$name}','{$last_name}')"; $result = pg_query($query); if (!$result) { printf("ERROR"); $errormessage = pg_errormessage($db); echo $errormessage; exit; } } }