Пример #1
0
 public static function castLink($link, array $a, Stub $stub, $isNested)
 {
     $a['status'] = pg_connection_status($link);
     $a['status'] = new ConstStub(PGSQL_CONNECTION_OK === $a['status'] ? 'PGSQL_CONNECTION_OK' : 'PGSQL_CONNECTION_BAD', $a['status']);
     $a['busy'] = pg_connection_busy($link);
     $a['transaction'] = pg_transaction_status($link);
     if (isset(self::$transactionStatus[$a['transaction']])) {
         $a['transaction'] = new ConstStub(self::$transactionStatus[$a['transaction']], $a['transaction']);
     }
     $a['pid'] = pg_get_pid($link);
     $a['last error'] = pg_last_error($link);
     $a['last notice'] = pg_last_notice($link);
     $a['host'] = pg_host($link);
     $a['port'] = pg_port($link);
     $a['dbname'] = pg_dbname($link);
     $a['options'] = pg_options($link);
     $a['version'] = pg_version($link);
     foreach (self::$paramCodes as $v) {
         if (false !== ($s = pg_parameter_status($link, $v))) {
             $a['param'][$v] = $s;
         }
     }
     $a['param']['client_encoding'] = pg_client_encoding($link);
     $a['param'] = new EnumStub($a['param']);
     return $a;
 }
Пример #2
0
function conectarse()
{
    if (!($conn = pg_connect("host=localhost user=postgres port=5432 dbname=eroGames password=123456"))) {
        echo "Error conectando a la base de datos.";
        exit;
    }
    if (!pg_dbname()) {
        echo "Error seleccionando la base de datos.";
        exit;
    }
    return $conn;
}
Пример #3
0
 public function connect()
 {
     $db = pg_connect("dbname=" . $this->context->database . " host=" . $this->context->host . " user="******" password=" . $this->context->password);
     # $this->context->host, $this->context->dbuser, $this->context->password);
     if (!$db) {
         $this->setError($this->context->getErrorMessage('bReport_noconnection', $this->context->dbuser, $this->context->host, pg_last_error()));
         return FALSE;
     }
     if (!pg_dbname($db)) {
         $this->close($db);
         $this->setError($this->context->getErrorMessage('bReport_nodb'));
         return FASLE;
     }
     return $db;
 }
Пример #4
0
 public function selectDb($dbName)
 {
     if (!is_string($dbName)) {
         throw new DbControlException("Ilegal parameter dbName. Must be string.");
     }
     $this->dbName = $dbName;
     if (is_resource($this->connection)) {
         if (@pg_dbname($this->connection) == $this->dbName) {
             return;
         }
     }
     try {
         $this->connect();
     } catch (Exception $e) {
         $this->throwPgsqlException("Cannot select DB: " . $e->getMessage());
     }
 }
Пример #5
0
 public function connect($db_host, $db_user, $db_pass, $db_name = null)
 {
     // this gets called in php5.
     $this->db_host = $db_host;
     $this->db_user = $db_user;
     $this->db_pass = $db_pass;
     if (!$db_name) {
         $this->db_name = $db_user;
     }
     if (!$this->con) {
         // note '@' suppresses error messages.
         $this->myconn = @pg_connect("host=" . $this->db_host . " user="******" password="******" dbname=" . $this->db_name);
         // pg_connect() with variables defined at the start of Database class
         if ($this->myconn) {
             $seldb = @pg_dbname($this->myconn);
             // Credentials have been pass through pg_connect() now select the database
             if ($seldb) {
                 $this->con = true;
                 $this->numResults = 1;
                 return true;
                 // Connection has been made return TRUE
             } else {
                 $this->result = error_get_last();
                 return false;
                 // Problem selecting database return FALSE
             }
         } else {
             $this->result = error_get_last();
             return false;
             // Problem connecting return FALSE
         }
     } else {
         return true;
         // Connection has already been made return TRUE
     }
 }
Пример #6
0
 public function DbName()
 {
     return pg_dbname($this->connection);
 }
Пример #7
0
<?php

include 'db_conn.php';
var_dump($dbconn);
if ($dbconn == null) {
    echo "tumhari maa ki chut";
} else {
    echo pg_dbname($dbconn);
}
Пример #8
0
function run_sqls()
{
    global $SIDU;
    $conn = $SIDU['conn'][$SIDU[0]];
    $eng = $conn[1];
    $cook = $SIDU['cook'][$SIDU[0]];
    @tm_use_db($cook[1], $cook[2]);
    if ($_GET['sql'] == 'show vars') {
        $_POST['sqlcur'] = $eng == 'pg' ? 'SHOW ALL' : 'SHOW VARIABLES';
    } elseif (@substr($_GET['sql'], 0, 6) == 'FLUSH ') {
        if ($_GET['sql'] == 'FLUSH ALL') {
            $_POST['sqlcur'] = "FLUSH LOGS;\nFLUSH HOSTS;\nFLUSH PRIVILEGES;\nFLUSH TABLES;\nFLUSH STATUS;\nFLUSH DES_KEY_FILE;\nFLUSH QUERY CACHE;\nFLUSH USER_RESOURCES;\nFLUSH TABLES WITH READ LOCK";
        } else {
            $_POST['sqlcur'] = $_GET['sql'];
        }
    } elseif (@substr($_GET['sql'], 0, 9) == 'STATScol:') {
        $_POST['sqlcur'] = "SELECT " . @goodname(@substr($_GET['sql'], 9)) . ",count(*) FROM " . @goodname($cook[4]) . " GROUP BY 1 ORDER BY 2 DESC,1 LIMIT 20";
    } elseif ($_GET['sql']) {
        $_POST['sqlcur'] = $_GET['sql'];
    }
    $arr = @explode(chr(10), @strip($_POST['sqlcur'], 1, 0, 1));
    foreach ($arr as $v) {
        $v = @trim($v);
        if ($v) {
            $arr2[] = $v;
        }
    }
    $txt = @implode(chr(10), $arr2);
    $arr = @explode(";" . chr(10), $txt);
    foreach ($arr as $i => $sql) {
        $time_start = @microtime(true);
        $res = $eng == 'my' ? @mysql_query($sql) : ($eng == 'pg' ? @pg_query($sql) : @sqlite_query($SIDU['dbL'], $sql));
        $time_end = @microtime(true);
        $time = @round(($time_end - $time_start) * 1000);
        $SIDU[5] += $time;
        $err = @sidu_err(1);
        $RES[$i][0] = $sql;
        if ($err) {
            $RES[$i][1] = $err;
            $SIDU[8]++;
        } else {
            $RES[$i][3] = $eng == 'my' ? @mysql_num_rows($res) : ($eng == 'pg' ? @pg_num_rows($res) : @sqlite_num_rows($res));
            if ($eng == 'pg' && !$RES[$i][3]) {
                $RES[$i][2] = @pg_affected_rows($res);
                if (!$RES[$i][2]) {
                    unset($RES[$i][2]);
                }
            }
            //there is no function: sqlite_affected_rows()
            if ($RES[$i][3] === false && $eng == 'my') {
                $RES[$i][2] = @mysql_affected_rows();
            }
            if (!isset($SIDU[6]) && $RES[$i][3] !== false) {
                $SIDU[6] = $i;
                $RES[$i][5] = @get_sql_col($res, $eng);
                $RES[$i][6] = @get_sql_data($res, $eng);
            } elseif ($_POST['sqlmore'] && $RES[$i][3] !== false) {
                $RES[$i][5] = @get_sql_col($res, $eng);
                $RES[$i][6] = @get_sql_data($res, $eng);
            }
            $RES[$i][4] = $time;
        }
        @tm_his_log('S', $sql, $time, $err);
    }
    $SIDU[7] = ++$i;
    $SIDU['RES'] = $RES;
    //reset cookie
    if ($eng == 'my') {
        $db = @mysql_fetch_row(@mysql_query("SELECT database()"));
        if ($db[0] != $cook[1]) {
            $ck = @array($conn[0], $db[0]);
        }
    } elseif ($eng == 'pg') {
        $db[0] = @pg_dbname();
        if ($db[0] != $cook[1]) {
            $ck = @array($conn[0], $db[0]);
        } else {
            //sch
            $sch = pg_fetch_row(pg_query("SHOW search_path"));
            if (@substr($sch[0], 0, 8) == '"$user",') {
                $sch[0] = @substr($sch[0], 8);
            }
            $sch[0] = @str_replace('"', '', $sch[0]);
            if ($sch[0] != $cook[2]) {
                $ck = @array($conn[0], $cook[1], $sch[0]);
            }
        }
    }
    if (isset($ck)) {
        @update_sidu_cook($ck);
    }
}
Пример #9
0
 /**
  * @param string $tableName
  * @throws \Exception
  * @return bool
  */
 public function existsTable($tableName)
 {
     $dbName = pg_dbname($this->dbConnection);
     $sql = "SELECT count(*) cnt FROM information_schema.tables WHERE table_catalog='{$dbName}' AND table_name='" . strtolower($tableName) . "'";
     $res = pg_query($this->dbConnection, $sql);
     if (!$res && pg_connection_status($this->dbConnection) === PGSQL_CONNECTION_OK) {
         throw new \Exception(pg_last_error($this->dbConnection));
     } else {
         if (!$res) {
             throw new \Exception('DB connection lost');
         }
     }
     $row = pg_fetch_assoc($res);
     pg_free_result($res);
     return $row['cnt'] > 0;
 }
Пример #10
0
    echo "pg_connection_status() error\n";
}
if (!pg_connection_reset($db)) {
    echo "pg_connection_reset() error\n";
}
if (pg_connection_busy($db)) {
    echo "pg_connection_busy() error\n";
}
if (function_exists('pg_transaction_status')) {
    if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE) {
        echo "pg_transaction_status() error\n";
    }
}
if (false === pg_host($db)) {
    echo "pg_host() error\n";
}
if (!pg_dbname($db)) {
    echo "pg_dbname() error\n";
}
if (!pg_port($db)) {
    echo "pg_port() error\n";
}
if (pg_tty($db)) {
    echo "pg_tty() error\n";
}
if (pg_options($db)) {
    echo "pg_options() error\n";
}
pg_close($db);
?>
===DONE===
Пример #11
0
 public function list_tables($like = NULL)
 {
     $dbname = pg_dbname($this->_connection);
     // This screams mysql, but we're pg so we're going to muck with this a bit.`
     if (is_string($like)) {
         // Search for table names
         $result = $this->query(\DB::SELECT, "\n\t\tSELECT table_name\n\t\tFROM information_schema.tables\n\t\tWHERE table_name ILIKE '%" . $this->quote($like) . "%' AND\n\t\ttable_catalog = '{$dbname}'\n\t\t", true);
     } else {
         // Find all table names
         $result = $this->query(\DB::SELECT, "\n\t\tSELECT table_name\n\t\tFROM information_schema.tables\n\t\tWHERE table_catalog = '{$dbname}'\n\t\t", true);
     }
     $tables = array();
     foreach ($result as $row) {
         $tables[] = $row->table_name;
     }
     return $tables;
 }