Ejemplo n.º 1
5
function removeLikeToTable($dbconn, $userId, $msgId)
{
    pg_prepare($dbconn, "deleteLikes", "DELETE FROM yakLikes WHERE userID = \$1 AND msgID = \$2");
    $sql = pg_execute($dbconn, "deleteLikes", array($userId, $msgId));
    pg_prepare($dbconn, "updateLikes", "UPDATE yak SET likes=(likes-1) WHERE id = \$1");
    $sql = pg_execute($dbconn, "updateLikes", array($msgId));
}
Ejemplo n.º 2
5
 public function execQry()
 {
     $recordString = false;
     switch ($this->connectorStructure['dbType']) {
         case "ORA":
             $connectorString = '(DESCRIPTION = (CONNECT_TIMEOUT=5) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =' . $this->connectorStructure['dbIP'] . ')(PORT = ' . $this->connectorStructure['dbPort'] . ')))(CONNECT_DATA=(SID= ' . $this->connectorStructure['dbName'] . ')))';
             $dbConnector = oci_connect($this->connectorStructure['dbUser'], $this->connectorStructure['dbPassword'], $connectorString);
             if (!$dbConnector) {
                 echo 'Failed connection.......';
             } else {
                 $oraQuery = oci_parse($dbConnector, $this->queryStructure['dbQuery']);
             }
             oci_execute($oraQuery);
             $rowsnum = oci_fetch_all($oraQuery, $recordString);
             if ($rowsnum == 0) {
                 $recordString = array();
             } else {
                 if (!(substr($this->queryStructure['dbQuery'], 1, 6) == 'select')) {
                     $oraQuery = oci_parse($dbConnector, 'commit');
                     oci_execute($oraQuery);
                     $rowsnum = oci_fetch_all($oraQuery, $recordString);
                 }
             }
             oci_close($dbConnector);
             break;
         case "PGS":
             $connectorString = "host=" . $this->connectorStructure['dbIP'] . " port=" . $this->connectorStructure['dbPort'] . " dbname=" . $this->connectorStructure['dbName'] . " user="******" password=" . $this->connectorStructure['dbPassword'];
             $dbConnector = pg_connect($connectorString);
             if (!$dbConnector) {
                 echo 'Failed connection.......';
             } else {
                 pg_prepare($dbConnector, $this->queryStructure['qryName'], $this->queryStructure['dbQuery']);
             }
             $queryResult = pg_execute($dbConnector, $this->queryStructure['qryName'], $this->queryStructure['qryParameters']);
             if (!$queryResult) {
                 $recordString = array();
             } else {
                 $recordString = pg_fetch_all($queryResult);
                 if (!(substr($this->queryStructure['dbQuery'], 1, 6) == 'select')) {
                     pg_prepare($dbConnector, 'commit', 'commit');
                     pg_exec($dbConnector, 'commit');
                 }
             }
             pg_close($dbConnector);
             break;
         default:
             $recordString = false;
             break;
     }
     return $recordString;
 }
Ejemplo n.º 3
0
function lookup_user($usr_id, $cur_time)
{
    // check if user exists (if not, create user)
    // check if url exists (if not, create url)
    // add vote
    if ($con = connect_db('../auth.txt')) {
        $result = pg_prepare($con, "check_user", 'SELECT * FROM users where id = $1');
        $result = pg_execute($con, "check_user", array($usr_id));
        $usr_entry = pg_fetch_array($result);
        pg_free_result($result);
        if (!$usr_entry) {
            $result = pg_prepare($con, "reg_user", 'INSERT INTO users VALUES ($1, $2, $3)');
            $result = pg_execute($con, "reg_user", array($usr_id, 0, (int) $cur_time));
            pg_free_result($result);
            $id = $usr_id;
            $spent = 0;
            $reg = $cur_time;
        } else {
            $id = $usr_entry[0];
            $spent = $usr_entry[1];
            $reg = $usr_entry[2];
        }
        echo json_encode(array("usr" => $id, "spent" => $spent, "reg" => $reg));
    } else {
        echo json_encode(array("f**k" => "nuts"));
    }
}
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);
}
Ejemplo n.º 5
0
 /**
  * Executes a prepared statement.
  *
  * @param $statement The name of the statement to execute.
  * @param $params The parameters to the statement.
  *
  * @return Whether the query was successful.
  */
 public function execute($statement, $params)
 {
     $result = pg_execute($this->connection, $statement, $params);
     $this->result = $result;
     $this->setError($result);
     $this->checkDie($result);
     return pg_fetch_array($result);
 }
Ejemplo n.º 6
0
 /**
  * prepare query
  * */
 public function execStatement($sql, $params)
 {
     $this->connect();
     $result = pg_prepare($this->connection, 'myStmt', $sql);
     pg_execute($this->connection, 'myStmt', $params);
     $this->disconnect();
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * @param $sql
  */
 protected function executeQuery($sql)
 {
     $id = 9;
     $name = "BMW";
     $price = 36000;
     $sql = "INSERT INTO cars VALUES(\$1, \$2, \$3)";
     pg_prepare($this->connection, "prepare1", $sql) or die("Cannot prepare statement\n");
     pg_execute($this->connection, "prepare1", array($id, $name, $price)) or die("Cannot execute statement\n");
 }
function inside_allowed_area_check($wkt)
{
    pg_prepare("", "SELECT ST_Within(ST_GeometryFromText(\$1, 25833), klarschiff.klarschiff_stadtgrenze_hro.the_geom) FROM klarschiff.klarschiff_stadtgrenze_hro");
    $result = pg_execute("", array($wkt));
    if ($row = pg_fetch_assoc($result)) {
        return $row['st_within'] === 't';
    }
    return false;
}
Ejemplo n.º 9
0
 private function executeUpdate($query, $params)
 {
     $result = pg_prepare($this->connection, "query", $query);
     if ($params) {
         $resultSet = pg_execute($this->connection, "query", $params);
     } else {
         $resultSet = pg_execute($this->connection, "query");
     }
     return pg_affected_rows($resultSet);
 }
Ejemplo n.º 10
0
 function getState($state)
 {
     $ret = array();
     $rs = pg_prepare($this->dbconn, "STATESELECT", sprintf("select *,\n    ST_x(s.geom) as x, ST_y(s.geom) as y, valid at time zone '%s' as lvalid,\n    max_gust_ts at time zone '%s' as lmax_gust_ts,\n    max_sknt_ts at time zone '%s' as lmax_sknt_ts,\n  \t\t\tvalid at time zone 'UTC' as utc_valid,\n    s.name as sname from\n    current c2, summary_%s c, stations s WHERE\n    s.state = \$1 and (s.network ~* 'RWIS' or s.network ~* 'ASOS' or\n  \t\t\ts.network in ('KCCI','KELO','KIMT') or network = 'AWOS') \n    and c.day = 'TODAY'\n    and c2.valid > 'TODAY' and c2.iemid = c.iemid and c.iemid = s.iemid", $this->tzname, $this->tzname, $this->tzname, date("Y")));
     $rs = pg_execute($this->dbconn, "STATESELECT", array($state));
     for ($i = 0; $row = @pg_fetch_array($rs, $i); $i++) {
         $ret[$row["id"]] = new IEMAccessOb($row);
     }
     return $ret;
 }
Ejemplo n.º 11
0
function place_by_name($name)
{
    global $conn;
    $result = pg_execute($conn, "place_by_name", array($name));
    $place = array();
    while ($row = pg_fetch_assoc($result)) {
        $place = $row;
    }
    pg_free_result($result);
    return $place;
}
Ejemplo n.º 12
0
 function load_station($id)
 {
     $rs = pg_execute($this->dbconn, "SELECTST", array($id));
     for ($i = 0; $row = @pg_fetch_array($rs, $i); $i++) {
         $this->table[$row["id"]] = $row;
     }
     if (pg_num_rows($rs) < 1) {
         return false;
     }
     return true;
 }
Ejemplo n.º 13
0
function get_iemprop($propname)
{
    $dbconn = iemdb("mesosite");
    $rs = pg_prepare($dbconn, "SELECT321" . $propname, "SELECT * from properties where\n        propname = \$1");
    $rs = pg_execute($dbconn, "SELECT321" . $propname, array($propname));
    if (pg_num_rows($rs) < 1) {
        return null;
    }
    $row = pg_fetch_array($rs, 0);
    return $row["propvalue"];
}
Ejemplo n.º 14
0
function getGlobalDefaults($dbconn)
{
    $defaults = array("ms_tol" => 6, "ms2_tol" => 20, "ms_tol_unit" => "ppm", "ms2_tol_unit" => "ppm", "missed_cleavages" => 4, "notes" => "", "customsettings" => "", "acquisitions" => array(), "sequences" => array());
    $getMultiOptions = array("enzyme" => "SELECT id FROM enzyme WHERE is_default = TRUE", "ions" => "SELECT id FROM ion WHERE is_default = TRUE", "crosslinkers" => "SELECT id FROM crosslinker WHERE is_default = TRUE", "losses" => "SELECT id FROM loss WHERE is_default = TRUE", "fixedMods" => "SELECT id FROM modification WHERE is_default_fixed = TRUE", "varMods" => "SELECT id FROM modification WHERE is_default_var = TRUE");
    foreach ($getMultiOptions as $key => $value) {
        pg_prepare($dbconn, $key, $value);
        $result = pg_execute($dbconn, $key, array());
        $defaults[$key] = resultsAsArray($result);
    }
    //error_log (print_r($defaults, TRUE));
    return $defaults;
}
Ejemplo n.º 15
0
function neighbors($station, $lat, $lon)
{
    $con = iemdb("mesosite");
    $rs = pg_prepare($con, "_SELECT", "SELECT *,\n         ST_distance(ST_transform(geom,3857), \n                     ST_transform(ST_GeomFromEWKT('SRID=4326;POINT(" . $lon . " " . $lat . ")'), 3857)) /1000.0 as dist from stations \n         WHERE ST_point_inside_circle(geom, " . $lon . ", " . $lat . ", 0.25) \n         and id != \$1 ORDER by dist ASC");
    $result = pg_execute($con, "_SELECT", array($station));
    $s = "<table class=\"table table-striped\">\n   <thead><tr><th>Distance [km]</th><th>Network</th><th>Station Name</th></tr></thead>";
    for ($i = 0; $row = @pg_fetch_assoc($result, $i); $i++) {
        $s .= sprintf("<tr><td>%.3f</td><td><a href=\"locate.php?network=%s\">%s</a></td><td><a href=\"site.php?station=%s&network=%s\">%s</a></td></tr>", $row["dist"], $row["network"], $row["network"], $row["id"], $row["network"], $row["name"]);
    }
    $s .= "</table>";
    return $s;
}
Ejemplo n.º 16
0
function get_iemapps_tags($tagname)
{
    // Get a html list for this tagname
    $pgconn = iemdb("mesosite", TRUE, TRUE);
    $rs = pg_prepare($pgconn, "TAGSELECT", "SELECT name, description, url from iemapps WHERE " . "appid in (SELECT appid from iemapps_tags WHERE tag = \$1) " . "ORDER by name ASC");
    $rs = pg_execute($pgconn, "TAGSELECT", array($tagname));
    $s = "<ul>";
    for ($i = 0; $row = @pg_fetch_assoc($rs, $i); $i++) {
        $s .= sprintf("<li><a href=\"%s\">%s</a><br />%s</li>\n", $row["url"], $row["name"], $row["description"]);
    }
    $s .= "</ul>";
    return $s;
}
Ejemplo n.º 17
0
function login()
{
    $schema = "feedmati_system";
    $conn = dbconnect();
    $user = $_POST['username'];
    $loginQuery = "SELECT * FROM {$GLOBALS['schema']}.authentication WHERE user_email = \$1";
    $stmt = pg_prepare($conn, "login", $loginQuery);
    echo pg_result_error($stmt);
    if (!$stmt) {
        echo "Error, can't prepare login query<br>";
        return;
    }
    $result = pg_execute($conn, "login", array($user));
    if (pg_num_rows($result) == 0) {
        echo "Username or Password is incorrect";
        return;
    }
    $saltQuery = "SELECT salt FROM {$GLOBALS['schema']}.authentication WHERE user_email = \$1";
    $saltPrepare = pg_prepare($conn, "salt", $saltQuery);
    if (!$saltPrepare) {
        echo "Could not sanitize query for salt";
        return;
    }
    $saltResult = pg_execute($conn, "salt", array($user));
    if (pg_num_rows($saltResult) > 0) {
        $saltRow = pg_fetch_assoc($saltResult);
        $salt = $saltRow['salt'];
        $salt = trim($salt);
        $saltedpw = sha1($_POST['password'] . $salt);
    }
    $userPassPrepare = pg_prepare($conn, "pwquery", "SELECT * FROM {$GLOBALS['schema']}.authentication WHERE user_email = \$1 AND password_hash = \$2");
    if (!$userPassPrepare) {
        echo "Error, can't prepare username password query<br>";
    }
    $user = $_POST['username'];
    $pwq = array($user, $saltedpw);
    $userPassResult = pg_execute($conn, "pwquery", $pwq);
    $numrows = pg_num_rows($userPassResult);
    //if there is a match it logs the person in and adds an entry to the log
    if ($numrows == 1) {
        $action = "login";
        $_SESSION['user'] = $user;
        $userPassRow = pg_fetch_assoc($userPassResult);
        $fname = $userPassRow['fname'];
        $_SESSION['fname'] = $fname;
        header("Location: home.php");
    } else {
        echo "Username or Password is incorrect";
    }
    pg_close($conn);
}
function validate_meldung_in_aoi($point)
{
    $connection_string = sprintf("host=%s dbname=%s user=%s password=%s", KS_DBSERVER, KS_DB, KS_OWNER, KS_PW);
    $connection = pg_connect($connection_string);
    // Retrieve all data from georss_polygone
    $data = array();
    pg_prepare("", "SELECT ST_Within(ST_GeometryFromText(\$1, 25833), klarschiff.klarschiff_stadtgrenze_hro.the_geom) FROM klarschiff.klarschiff_stadtgrenze_hro");
    $result = pg_execute("", array($point));
    if ($row = pg_fetch_assoc($result)) {
        return $row["st_within"] == 't';
    }
    pg_close($connection);
    return false;
}
Ejemplo n.º 19
0
 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;
 }
Ejemplo n.º 20
0
function getUserRights($dbconn, $userID)
{
    pg_prepare($dbconn, "user_rights", "SELECT * FROM users WHERE id = \$1");
    $result = pg_execute($dbconn, "user_rights", [$userID]);
    $row = pg_fetch_assoc($result);
    //error_log (print_r ($row, true));
    $canSeeAll = !isset($row["see_all"]) || $row["see_all"] === 't';
    // 1 if see_all flag is true or if that flag doesn't exist in the database
    $canAddNewSearch = !isset($row["can_add_search"]) || $row["can_add_search"] === 't';
    // 1 if can_add_search flag is true or if that flag doesn't exist in the database
    $isSuperUser = isset($row["super_user"]) && $row["super_user"] === 't';
    // 1 if super_user flag is present AND true
    return array("canSeeAll" => $canSeeAll, "canAddNewSearch" => $canAddNewSearch, "isSuperUser" => $isSuperUser);
}
function get_rss_data($id)
{
    $connection_string = sprintf("host=%s dbname=%s user=%s password=%s", KS_DBSERVER, KS_DB, KS_OWNER, KS_PW);
    $connection = pg_connect($connection_string);
    // Retrieve all data from georss_polygone
    $data = array();
    pg_prepare("", "SELECT g.ideen, g.ideen_kategorien, g.probleme, g.probleme_kategorien, ST_AsText(g.the_geom) AS wkt FROM klarschiff.klarschiff_geo_rss g WHERE md5(g.id::varchar)=\$1");
    $result = pg_execute("", array($id));
    if ($row = pg_fetch_assoc($result)) {
        $data = $row;
    }
    pg_close($connection);
    return $data;
}
function trashmail_check($email)
{
    $connection_string = sprintf("host=%s dbname=%s user=%s password=%s", KS_DBSERVER, KS_DB, KS_OWNER, KS_PW);
    $connection = pg_connect($connection_string);
    $blacklist_this = false;
    if ($connection) {
        pg_prepare('', "SELECT COUNT(*) FROM klarschiff.klarschiff_trashmail_blacklist WHERE \$1 LIKE '%@' || pattern OR \$2 LIKE '%.' || pattern");
        $result = pg_execute('', array($_REQUEST['email'], $_REQUEST['email']));
        if ($row = pg_fetch_assoc($result)) {
            $blacklist_this = $row["count"] !== '0';
        }
        pg_close($connection);
    }
    return $blacklist_this ? '1001#1001#Ihre E-Mail-Adresse wird nicht akzeptiert, da sie auf unserer Trashmail-Blacklist steht.' : false;
}
Ejemplo n.º 23
0
function trashmail_check($config, $email)
{
    $db_config = $config['database']['frontend'];
    $connection = pg_connect("host=" . $db_config['host'] . " port=" . $db_config['port'] . " dbname=" . $db_config['dbname'] . " user="******" password="******"");
    $blacklist_this = false;
    if ($connection) {
        pg_prepare('', "SELECT COUNT(*) FROM klarschiff.klarschiff_trashmail_blacklist WHERE \$1 LIKE '%@' || pattern OR \$2 LIKE '%.' || pattern");
        $result = pg_execute('', array($_REQUEST['email'], $_REQUEST['email']));
        if ($row = pg_fetch_assoc($result)) {
            $blacklist_this = $row["count"] !== '0';
        }
        pg_close($connection);
    }
    return $blacklist_this ? '1001#1001#' . $config['labels']['errors']['mail_on_blacklist'] : false;
}
Ejemplo n.º 24
0
 public function loginUser($username, $password)
 {
     $conn = $this->connectProd();
     $encrypted_password = md5($password);
     //prepare sql
     $result = pg_prepare($conn, "my_query", 'select * from tb_users where username = $1 and password = $2');
     $result = pg_execute($conn, "my_query", array($username, $encrypted_password)) or die("Error during query.");
     $rows = pg_numrows($result);
     if (!$rows) {
         pg_close($conn);
         return;
     } else {
         $status = 'ok';
         pg_close($conn);
         return $status;
     }
 }
Ejemplo n.º 25
0
function find_family($p)
{
    // Find a person's children and their coparents
    $handle = pg_execute("family", array($p));
    $count = 0;
    while ($row = pg_fetch_row($handle)) {
        $family[$count][0] = $row[0];
        // child
        $family[$count][1] = $row[1];
        // coparent
        $count++;
    }
    if (isset($family)) {
        return $family;
    } else {
        return false;
    }
}
Ejemplo n.º 26
0
function cast_vote($url, $usr_id, $time_spent, $time_reg)
{
    // check if user exists (if not, create user)
    // check if url exists (if not, create url)
    // add vote
    if ($con = connect_db('../auth.txt')) {
        $result = pg_prepare($con, "check_user", 'SELECT * FROM users where id = $1');
        $result = pg_execute($con, "check_user", array($usr_id));
        $usr_entry = pg_fetch_array($result);
        pg_free_result($result);
        if (!$usr_entry) {
            $result = pg_prepare($con, "register_user", 'INSERT INTO users VALUES ($1, $2, $3)');
            $result = pg_execute($con, "register_user", array($usr_id, $time_spent, $time_reg));
            pg_free_result($result);
        } else {
            $time_already_spent = $usr_entry[1];
            $new_time_spent = $time_already_spent + $time_spent;
            $result = pg_prepare($con, "update_user", 'UPDATE users SET time_spent=$2 WHERE id=$1');
            $result = pg_execute($con, "update_user", array($usr_id, $new_time_spent));
            pg_free_result($result);
        }
        $result = pg_prepare($con, "check_url", 'SELECT * FROM votes where url = $1');
        $result = pg_execute($con, "check_url", array($url));
        $url_entry = pg_fetch_array($result);
        pg_free_result($result);
        if (!$url_entry) {
            //create url entry, add vote time
            $result = pg_prepare($con, "register_url", 'INSERT INTO votes VALUES ($1, $2)');
            $result = pg_execute($con, "register_url", array($url, $time_spent));
            pg_free_result($result);
        } else {
            //update vote time
            $vote_count = $url_entry[1];
            $new_count = $vote_count + $time_spent;
            $result = pg_prepare($con, "update_votes", 'UPDATE votes SET votes=$2 WHERE url=$1');
            $result = pg_execute($con, "update_votes", array($url, $new_count));
            pg_free_result($result);
        }
        $id = $usr_entry[0];
        $spent = $usr_entry[1];
        $reg = $usr_entry[2];
        echo json_encode(array("usr" => $id, "spent" => $time_spent, "reg" => $reg, "url" => $url));
    }
}
Ejemplo n.º 27
0
function check_password($email, $password)
{
    global $DBHOST, $DBNAME, $DBUSER, $DBPASS;
    global $ZKSALT, $ZKITERATIONS;
    $dbconn = pg_connect("host={$DBHOST} dbname={$DBNAME} user={$DBUSER} password={$DBPASS}") or die('Could not connect: ' . pg_last_error());
    pg_prepare($dbconn, "pwcheck", 'SELECT password_hash, password_salt FROM person WHERE email_address = $1');
    $result = pg_execute($dbconn, "pwcheck", array($email));
    $expectedhash = pg_fetch_result($result, 0, 'password_hash');
    $usersalt = pg_fetch_result($result, 0, 'password_salt');
    pg_free_result($result);
    pg_close($dbconn);
    print "\t ZK:\t" . $expectedhash . "\n";
    $salt = $ZKSALT . $usersalt;
    // FIXME: switch back to PBKDF2 once Python 2.7.8 is in Ubuntu LTS (16.04)
    //$computedhash = hash_pbkdf2('sha256', $password, $salt, $ZKITERATIONS);
    $computedhash = hash('sha256', $password . $salt);
    print "\t PHP:\t" . $computedhash . "\n";
    return $expectedhash === $computedhash;
}
Ejemplo n.º 28
0
function download_data($sts, $ets)
{
    $dbconn = iemdb('other');
    $rs = pg_prepare($dbconn, "SELECT", "SELECT * from asi_data WHERE\n\t\t\tvalid >= \$1 and valid < \$2 ORDER by valid ASC");
    $rs = pg_execute($dbconn, "SELECT", array(date("Y-m-d", $sts), date("Y-m-d", $ets)));
    header("Content-type: text/plain");
    echo "station,valid,";
    for ($i = 1; $i < 13; $i++) {
        echo sprintf("ch%savg,ch%ssd,ch%smax,ch%smin,", $i, $i, $i, $i);
    }
    echo "\n";
    for ($i = 0; $row = @pg_fetch_assoc($rs, $i); $i++) {
        echo sprintf("%s,%s,", $row['station'], $row['valid']);
        for ($j = 1; $j < 13; $j++) {
            echo sprintf("%s,%s,%s,%s,", $row["ch{$j}avg"], $row["ch{$j}sd"], $row["ch{$j}max"], $row["ch{$j}min"]);
        }
        echo "\n";
    }
}
Ejemplo n.º 29
0
function newEggs()
{
    global $dbconn;
    global $conf;
    stream_context_set_default(array('http' => array('method' => 'GET', 'header' => "X-ApiKey: " . $conf["apikey"])));
    // query all "münster aqe" eggs
    // 2 methods available:
    // search by tags "aqe münster"...
    $params1 = "?tag=" . urlencode("münster") . "&tag=aqe";
    // ... or search by spatial radius - we are using this one
    // find eggs around 51.95N 7.63E with radius 25 kilometers
    $params2 = "?lat=" . urlencode($conf["location"]["lat"]) . "&lon=" . urlencode($conf["location"]["lon"]) . "&distance=25.0&distance_units=kms&q=aqe";
    if (!($result = pg_prepare($dbconn, 'egginsert', 'INSERT INTO eggs (cosmid, geom, about, link) VALUES ($1, ST_GeomFromText($2, 4326), $3, $4)'))) {
        echo "Prepared statement failed, please check database structure.<br>";
    }
    $f = @file_get_contents("http://api.cosm.com/v2/feeds/" . $params2);
    $d = json_decode($f, true);
    echo "Found " . count($d["results"]) . "<hr>";
    foreach ($d["results"] as $egg) {
        // duplicate check
        $duplicate_result = pg_query_params($dbconn, 'SELECT eggid FROM eggs WHERE cosmid=$1', array($egg["id"]));
        if (pg_num_rows($duplicate_result) >= 1) {
            echo "Cosm id " . $egg["id"] . " ignored, already in database<br>";
        } else {
            // insert new eggs into database
            $point = "POINT(" . $egg["location"]["lon"] . " " . $egg["location"]["lat"] . ")";
            if (!($result = @pg_execute($dbconn, 'egginsert', array($egg["id"], $point, $egg["title"], "https://cosm.com/feeds/" . $egg["id"])))) {
                $error = pg_last_error();
                echo $error . "<br>";
            } else {
                echo 'Added Egg ID ' . $egg["id"] . " with location (";
                echo $egg["location"]["lon"] . "|";
                echo $egg["location"]["lat"] . ")<br>";
            }
        }
    }
    /*$log = print_r($eggs, true);
    	$logtext = $log.PHP_EOL.PHP_EOL;
    	file_put_contents("../log/query_eggs.txt", $logtext, FILE_APPEND);*/
}
Ejemplo n.º 30
0
 public function prepare($stmtName, $stmt, $values)
 {
     $result = pg_query_params($this->connection, 'SELECT name FROM pg_prepared_statements WHERE name = $1', array($stmtName));
     //var_dump($stmt);
     //var_dump($values);
     if (pg_num_rows($result) == 0) {
         $result = \pg_prepare($this->connection, $stmtName, $stmt);
         if (($info = \pg_last_notice($this->connection)) != '') {
             new \SYSTEM\LOG\INFO($info);
         }
     }
     if (!$result) {
         throw new \SYSTEM\LOG\ERROR('Prepared Statement prepare fail: ' . \pg_last_error($this->connection));
     }
     $result = \pg_execute($this->connection, $stmtName, $values);
     if (($info = \pg_last_notice($this->connection)) != '') {
         new \SYSTEM\LOG\INFO($info);
     }
     if (!$result) {
         throw new \SYSTEM\LOG\ERROR("Could not execute prepare statement: " . \pg_last_error($this->connection));
     }
     return new ResultPostgres($result, $this);
 }