function db_connect($host, $user, $pass, $db, $type, $port = false) { if ($type == "pgsql") { $string = "dbname={$db} user={$user}"; if ($pass) { $string .= " password={$pass}"; } if ($host) { $string .= " host={$host}"; } if ($port) { $string = "{$string} port=" . $port; } $link = pg_connect($string); return $link; } if ($type == "mysql") { if (function_exists("mysqli_connect")) { if ($port) { return mysqli_connect($host, $user, $pass, $db, $port); } return mysqli_connect($host, $user, $pass, $db); } $link = mysql_connect($host, $user, $pass); if ($link) { $result = mysql_select_db($db, $link); if ($result) { return $link; } } } }
public function conectar_bodega() { if (!isset($this->conexion)) { $this->conexion = pg_connect("host=localhost port=5432 dbname=proyecto user=administrador password=123456") or die("Error de conexion. " . pg_last_error()); return $this->conexion; } }
protected function _connect() { $connstr = ''; foreach ($this->_config as $param => $value) { if ($value) { switch ($param) { case 'host': $connstr .= "host={$value} "; break; case 'database': $connstr .= "dbname={$value} "; break; case 'port': $connstr .= "port={$value} "; break; case 'username': $connstr .= "user={$value} "; break; case 'password': $connstr .= "password={$value} "; break; } } } if (isset($this->_config['persistent'])) { $this->_connection = pg_pconnect($connstr); } else { $this->_connection = pg_connect($connstr); } if (pg_connection_status($this->_connection) !== PGSQL_CONNECTION_OK) { $this->_errorHandler(1, "Cconnection failed. "); } }
function db_connect($connection_name = false) { if ($this->db) { return true; } // Choose what to connect to if ($connection_name && $GLOBALS['AR_DB_CONFIG'][$connection_name]) { $this->default = $GLOBALS['AR_DB_CONFIG'][$connection_name]; $this->db_connection = $connection_name; } elseif ($this->db_connection && $GLOBALS['AR_DB_CONFIG'][$this->db_connection]) { $this->default = $GLOBALS['AR_DB_CONFIG'][$this->db_connection]; } else { $this->default = $GLOBALS['AR_DB_CONFIG'][AR_DEFAULT_DB]; $this->db_connection = AR_DEFAULT_DB; } // Get outta here if we have no good setting if (!$this->default['hostname']) { die('Please setup database.ini'); } // Connect if ($this->db = pg_connect("host={$this->default['hostname']} dbname={$this->default['database']} user={$this->default['login']} password={$this->default['password']}")) { // Connected ! } else { die('Unable to connect to database: ' . $this->default['database']); } return true; }
public function connect() { $this->linkid = pg_connect("host={$this->_config['host']}\n port={$this->_config['port']}\n dbname={$this->_config['database']}\n user={$this->_config['user']}\n password={$this->_config['password']}"); if (!$this->linkid) { throw new Exception("Could not connect to PostgreSQL server."); } }
public function __construct() { // - Connexion à la BD require_once "constantes.inc.php"; // - connexion à la base de données $this->db_connect = pg_connect("host=" . HOSTNAME . " dbname=" . BASE . " user="******" password=" . PASSWORD); }
function connect() { $this->hostName = MY_HOST; $this->port = MY_PORT; $this->userName = MY_USER; $this->password = MY_PASS; $this->databaseName = MY_BD; // build connection string based on internal settings. $connStr = ''; $this->hostName != '' ? $connStr .= "host=" . $this->hostName . " " : ($connStr = $connStr); $this->port != '' ? $connStr .= "port=" . $this->port . " " : ($connStr = $connStr); $this->databaseName != '' ? $connStr .= "dbname=" . $this->databaseName . " " : ($connStr = $connStr); $this->userName != '' ? $connStr .= "user="******" " : ($connStr = $connStr); $this->password != '' ? $connStr .= "password="******" " : ($connStr = $connStr); $connStr = trim($connStr); $connID = pg_connect($connStr); if ($connID != "") { $this->connectionID = $connID; $this->exec("set datestyle='ISO'", array()); $this->exec("set time zone 'America/Santiago'", array()); return $this->connectionID; } else { // FATAL ERROR - CONNECTI0N ERROR $this->errorCode = -1; $this->connectionID = -1; return 0; } }
function db_connect($dbtype = 'mysql') { $dbhost = 'localhost'; $dbuser = '******'; $dbpass = '******'; if ($dbtype == 'pear') { $dsn = array('phptype' => 'mysql', 'username' => $dbuser, 'password' => $dbpass, 'hostspec' => $dbhost); $options = array('debug' => 2, 'portability' => MDB2_PORTABILITY_ALL); // uses MDB2::factory() to create the instance // and also attempts to connect to the host $mdb2 = MDB2::connect($dsn, $options); if (PEAR::isError($mdb2)) { error($mdb2->getMessage()); } return $mdb2; } else { if ($dbtype == 'mysql') { $mysql_conn = mysqli_connect($dbhost, $dbuser, $dbpass); if (mysqli_connect_errno()) { error("MySQL : Connect failed: %s\n" . mysqli_connect_error()); } return $mysql_conn; } else { if ($dbtype == 'postgres') { $postgres_conn = pg_connect("host={$dbhost} user={$dbuser} password={$dbpass}"); if (!$postgres_conn) { error("PostGres : Connect failed: %s"); } return $postgres_conn; } } } }
/** * This is the connect function that tries to create a postgresql connection, and set the correct character set. */ protected function connect() { if (!function_exists("pg_connect")) { throw new DatabaseException("The function pg_connect is not available! Please install the postgresql php module."); } $connection_string = ""; if ($this->host) { $connection_string .= "host='" . pg_escape_string($this->host) . "' "; } if ($this->port) { $connection_string .= "port='" . pg_escape_string($this->port) . "' "; } if ($this->dbname) { $connection_string .= "dbname='" . pg_escape_string($this->dbname) . "' "; } if ($this->user) { $connection_string .= "user='******' "; } if ($this->password) { $connection_string .= "password='******' "; } $this->resource = pg_connect($connection_string); if (!$this->resource) { throw new DatabaseException("Sorry, impossible to connect to the server with this connection string: '" . $this->getConnectionString() . "'."); } $this->connected = true; pg_set_client_encoding($this->resource, $this->charsetName); if ($this->searchPath) { $this->query('set search_path to "' . pg_escape_string($this->searchPath) . '"'); } return true; }
function __construct() { /* $ORIONDBCFG_DB_host = "localhost"; $ORIONDBCFG_DB_user = "******"; $ORIONDBCFG_DB_password = "******"; $ORIONDBCFG_DB_dbname = "toelatingsexamen"; */ $connstring = ""; if ($ORIONDB_CFG_DB_host) { $connstring .= "host=" . $ORIONDB_CFG_DB_host . " "; } if ($ORIONDB_CFG_DB_dbname) { $connstring .= "dbname=" . $ORIONDB_CFG_DB_dbname . " "; } if ($ORIONDB_CFG_DB_user) { $connstring .= "user="******" "; } if ($ORIONDB_CFG_DB_password) { $connstring .= "password="******" "; } //$dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo"); //connect to a database named "mary" on the host "sheep" with a username and password $this->dbconnection = pg_connect($connstring) or die("Database connection failed"); // get tables $query = "SELECT NULL AS nspname, c.relname, \n\t\t\t\t\t(SELECT usename FROM pg_user u WHERE u.usesysid=c.relowner) AS relowner,\n\t\t\t\t\t(SELECT description FROM pg_description pd WHERE c.oid=pd.objoid) AS relcomment,\n\t\t\t\t\treltuples::bigint AS reltuples\n\t\t\t\tFROM pg_class c\n\t\t\t\tWHERE c.relkind='r'\n\t\t\t\t\tAND NOT EXISTS (SELECT 1 FROM pg_rewrite r WHERE r.ev_class = c.oid AND r.ev_type = '1')\n\t\t\t\t\tAND c.relname NOT LIKE 'pg@_%' ESCAPE '@' \n\t\t\t\t\tAND c.relname NOT LIKE 'sql@_%' ESCAPE '@'\n\t\t\t\tORDER BY relname"; }
function control() { global $result, $input, $userID; $conn = pg_connect("host=postgredb.ctnfr2pmdvmf.us-west-2.rds.amazonaws.com port=5432 dbname=postgreDB user=postgreuser password=6089qwerty"); if (!$conn) { echo "denied, an error occurred about connection.\n"; exit; } $query = "SELECT USERNAME,USERID FROM PALUSER WHERE USERNAME LIKE '{$input}%' AND USERID != '{$userID}'"; $result = pg_query($conn, $query); if (!$result) { echo "denied, an error occurred about query.\n"; return 0; } $names = ""; $ids = ""; $first = true; while ($row = pg_fetch_row($result)) { if ($first) { $names = $row[0]; $ids = $row[1]; $first = false; } else { $names = $names . " " . $row[0]; $ids = $ids . " " . $row[1]; } } if ($ids == "") { echo "denied, empty result"; } return $names . " " . $ids; }
private function dbconnect() { //$dbconn = pg_connect("host=" . DB_HOST . " dbname=" . DB_DB . " user="******" password="******"host=turing.centre.edu dbname=theaterDB user=visitorDrama password=Costumes4All") or die('Could not connect: ' . pg_last_error()); return $dbconn; }
public function connect($connectionString) { $this->connection = \pg_connect($connectionString); if (!$this->connection) { throw new \Exception('Failed to connect: ' . \pg_last_error($this->connection)); } }
function transform($x, $y, $oldEPSG, $newEPSG) { if (is_null($x) || !is_numeric($x) || is_null($y) || !is_numeric($y) || is_null($oldEPSG) || !is_numeric($oldEPSG) || is_null($newEPSG) || !is_numeric($newEPSG)) { return null; } if (SYS_DBTYPE == 'pgsql') { $con = db_connect(DBSERVER, OWNER, PW); $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as minx"; $resMinx = db_query($sqlMinx); $minx = floatval(db_result($resMinx, 0, "minx")); $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as miny"; $resMiny = db_query($sqlMiny); $miny = floatval(db_result($resMiny, 0, "miny")); } else { $con_string = "host=" . GEOS_DBSERVER . " port=" . GEOS_PORT . " dbname=" . GEOS_DB . "user="******"password="******"Error while connecting database"); /* * @security_patch sqli done */ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as minx"; $resMinx = pg_query($con, $sqlMinx); $minx = floatval(pg_fetch_result($resMinx, 0, "minx")); $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as miny"; $resMiny = pg_query($con, $sqlMiny); $miny = floatval(pg_fetch_result($resMiny, 0, "miny")); } return array("x" => $minx, "y" => $miny); }
function connect($db_conn_string, $db_search_path) { global $conn; $conn = pg_connect($db_conn_string) or die('Could not connect: ' . pg_last_error()); pg_query("SET search_path TO {$db_search_path}"); return $conn; }
function conectar($usuario, $contrasena) { $servidor = "localhost"; $puerto = "5432"; $dbname = "congresos"; $conexion = pg_connect("host=" . $servidor . " port=" . $puerto . " dbname=" . $dbname . " user="******" password="******"No se ha podido conectar con la base de datos" . pg_last_error()); }
/** Luo HTML sivustolaajuinen tagilistam\"{a}\"{a}r\"{a}t kysymykselle * @param $question_id integer */ function create_global_tag_count_box_for_a_question($question_id) { /* $result resource * $tags_array_summary array * $figure array */ $tags_array_summary = get_tags_for_a_question($question_id); $dbconn = pg_connect("host=localhost port=5432 dbname=noaa user=noaa password=123"); // to get the amout of tags Globally $result = pg_prepare($dbconn, "query_tag_amount", 'SELECT count(tag) FROM tags WHERE tag = $1'); echo "<div class='tags_summary'>"; echo "<p>tagged</p>"; for ($i = 0; $i < count($tags_array_summary); $i++) { echo "<div id='one_tag_line'>"; $result = pg_execute($dbconn, "query_tag_amount", array($tags_array_summary[$i]['tag'])); $figure = pg_fetch_all($result); for ($j = 0; $j < count($figure); $j++) { create_tags($tags_array_summary[$i]); echo "<span id='multiplier'> × " . $figure[$j]['count'] . "</span>"; } echo "</div>"; } echo "</div>"; }
private function __construct() { if (!($connection = pg_connect(self::DBN))) { throw new Exception("DBへの接続に失敗"); } $this->connection = $connection; }
function db_connect($host, $user, $pass, $db) { if (DB_TYPE == "pgsql") { $string = "dbname={$db} user={$user}"; if ($pass) { $string .= " password={$pass}"; } if ($host) { $string .= " host={$host}"; } if (defined('DB_PORT')) { $string = "{$string} port=" . DB_PORT; } $link = pg_connect($string); if (!$link) { die("Unable to connect to database (as {$user} to {$host}, database {$db}):" . pg_last_error()); } return $link; } else { if (DB_TYPE == "mysql") { $link = mysql_connect($host, $user, $pass); if ($link) { $result = mysql_select_db($db, $link); if (!$result) { die("Can't select DB: " . mysql_error($link)); } return $link; } else { die("Unable to connect to database (as {$user} to {$host}, database {$db}): " . mysql_error()); } } } }
function DBConnection($aDBInfo) { global $aQueries; // Initialize query array. $aQueries = array(); // Populate the special queries list. $this->aSpecialQueries[CONCAT_ATTACHMENT] = "UPDATE attachment SET filedata = filedata || '%s' WHERE id=%u"; $this->aSpecialQueries[CONCAT_AVATAR] = "UPDATE avatar SET datum = datum || '%s' WHERE id=%u"; // Some hosting providers aren't setup to accept "localhost" properly, // so only add the "host" parameter when the script is not connecting locally. if ($aDBInfo['address'] != 'localhost') { $host = "host='" . $aDBInfo['address'] . "' "; } // Try and connect to the database server. if ($this->objConnection = @pg_connect($host . "dbname='" . $aDBInfo['database'] . "' user='******'username'] . "' password='******'password'] . "'")) { // Destroy the database connection information. unset($aDBInfo['address']); unset($aDBInfo['username']); unset($aDBInfo['password']); unset($aDBInfo['database']); // Flag success. $this->objSelect = TRUE; } else { // Flag failure. $this->objSelect = FALSE; } }
private function __construct() { $this->handle = pg_connect("host=labdb dbname=bd user=fc359081 password=lel"); if (!$this->handle) { App::app()->add_info('Nie udało się połączyć z bazą danych ' . pg_last_error(), 'danger'); } }
function db($dbuser, $dbpassword, $dbname, $dbhost, $dbport = '') { $connect_str = ""; if (!empty($dbhost)) { $connect_str .= " host={$dbhost}"; } if (!empty($dbname)) { $connect_str .= " dbname={$dbname}"; } if (!empty($dbuser)) { $connect_str .= " user={$dbuser}"; } if (!empty($dbpassword)) { $connect_str .= " password={$dbpassword}"; } if (!empty($dbport)) { $connect_str .= " port={$dbport}"; } $this->dbh = @pg_connect($connect_str); if (!$this->dbh) { $this->print_error("<ol><b>Error establishing a database connection!</b><li>Are you sure you have the correct user/password?<li>Are you sure that you have typed the correct hostname?<li>Are you sure that the database server is running?<li></ol>"); } else { // Remember these values for the select function $this->dbuser = $dbuser; $this->dbpassword = $dbpassword; $this->dbname = $dbname; $this->dbhost = $dbhost; $this->dbport = $dbport; } }
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 DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect) { $this->prefix = $db_prefix; if ($db_host) { if (strpos($db_host, ':') !== false) { list($db_host, $dbport) = explode(':', $db_host); $connect_str[] = 'host=' . $db_host . ' port=' . $dbport; } else { $connect_str[] = 'host=' . $db_host; } } if ($db_name) { $connect_str[] = 'dbname=' . $db_name; } if ($db_username) { $connect_str[] = 'user='******'password='******' ', $connect_str)); } else { $this->link_id = @pg_connect(implode(' ', $connect_str)); } if (!$this->link_id) { error('Unable to connect to PostgreSQL server.', __FILE__, __LINE__); } // Setup the client-server character set (UTF-8) if (!defined('FORUM_NO_SET_NAMES')) { $this->set_names('utf8'); } return $this->link_id; }
/** Ota tagit tietokannasta * @return array */ function get_tags() { /* $result_tags array * $end_array array */ $dbconn = pg_connect("host=localhost port=5432 dbname=noaa user=noaa password=123"); $result_tags = pg_query_params($dbconn, 'SELECT question_id, tag FROM tags WHERE question_id IN ( SELECT question_id FROM tags WHERE tag = $1 ) ORDER BY question_id', array($_GET['tag'])); while ($tags_and_Qid = pg_fetch_array($result_tags)) { // Add the Tag to an array of tags for that question $end_array[$tags_and_Qid['question_id']]['tag'][] = $tags_and_Qid['tag']; } // to check if 0 messages if (count($end_array) == 0) { header("Location: index.php?" . "no_question_found"); } else { return $end_array; } }
/** * \brief Connect to database engine. * This is a no-op if $PG_CONN already has a value. * * \param $sysconfdir fossology configuration directory (location of Db.conf) * \param $Options an optional list of attributes for * connecting to the database. E.g.: * "dbname=text host=text user=text password=text" * \param $exitOnFail true (default) to print error and call exit on failure * false to return $PG_CONN === false on failure * * If $Options is empty, then connection parameters will be read from Db.conf. * * \return * Success: $PG_CONN, the postgres connection object * Failure: Error message is printed **/ function DBconnect($sysconfdir, $options = "", $exitOnFail = true) { global $PG_CONN; if (!empty($PG_CONN)) { return $PG_CONN; } $path = "{$sysconfdir}/Db.conf"; if (empty($options)) { $dbConf = file_get_contents($path); if ($exitOnFail && false === $dbConf) { $text = _("Could not connect to FOSSology database."); echo "<h2>{$text}</h2>"; echo _('permission denied for configuration file'); exit; } if (false === $dbConf) { $PG_CONN = false; return; } $options = $dbConf; } if (!empty($options)) { $PG_CONN = pg_connect(str_replace(";", " ", $options)); } if (!empty($PG_CONN)) { return $PG_CONN; } if ($exitOnFail) { $text = _("Could not connect to FOSSology database."); echo "<h2>{$text}</h2>"; exit; } $PG_CONN = false; }
function Open($dbType, $connectType = "c", $connect, $username = "", $password = "", $dbName) { switch ($dbType) { case "mssql": if ($connectType == "c") { $idCon = mssql_connect($connect, $username, $password); } else { $idCon = mssql_pconnect($connect, $username, $password); } mssql_select_db($dbName); break; case "mysql": if ($connectType == "c") { $idCon = @mysql_connect($connect, $username, $password); } else { $idCon = @mysql_pconnect($connect, $username, $password); } $idCon1 = mysql_select_db($dbName, $idCon); break; case "pg": if ($connectType == "c") { $idCon = pg_connect($connect . " user="******" password="******" dbname=" . $dbName); } else { $idCon = pg_pconnect($connect . " user="******" password="******" dbname=" . $dbName); } break; default: $idCon = 0; break; } return $idCon; }
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) { $this->connect_string = ""; if ($sqluser) { $this->connect_string .= "user={$sqluser} "; } if ($sqlpassword) { $this->connect_string .= "password={$sqlpassword} "; } if ($sqlserver) { if (ereg(":", $sqlserver)) { list($sqlserver, $sqlport) = split(":", $sqlserver); $this->connect_string .= "host={$sqlserver} port={$sqlport} "; } else { if ($sqlserver != "localhost") { $this->connect_string .= "host={$sqlserver} "; } } } if ($database) { $this->dbname = $database; $this->connect_string .= "dbname={$database}"; } $this->persistency = $persistency; $this->db_connect_id = $this->persistency ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string); return $this->db_connect_id ? $this->db_connect_id : false; }
/** * Static method get * * @param array $group * @return \helpers\database */ public static function get($group = false) { // Determining if exists or it's not empty, then use default group defined in config $group = !$group ? array('type' => DB_TYPE, 'host' => DB_HOST, 'name' => DB_NAME, 'user' => DB_USER, 'pass' => DB_PASS) : $group; // Group information $type = $group['type']; $host = $group['host']; $name = $group['name']; $user = $group['user']; $pass = $group['pass']; // ID for database based on the group information $id = "{$type}.{$host}.{$name}.{$user}.{$pass}"; // Checking if the same if (isset(self::$instances[$id])) { return self::$instances[$id]; } try { // I've run into problem where // SET NAMES "UTF8" not working on some hostings. // Specifiying charset in DSN fixes the charset problem perfectly! //$instance = new Database("$type:host=$host;dbname=$name;charset=utf8", $user, $pass); $instance = pg_connect("host={$host} port=5432 dbname={$name} user={$user} password={$pass}"); $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting Database into $instances to avoid duplication self::$instances[$id] = $instance; return $instance; } catch (PDOException $e) { //in the event of an error record the error to ErrorLog.html Logger::newMessage($e); Logger::customErrorMsg(); } }
function connect() { global $php_errormsg; $persistent = isset($this->config['persistent']) ? $this->config['persistent'] : null; $connstr = ''; if ($host = $this->config['host']) { $connstr = 'host=' . $host; } if ($port = $this->config['port']) { $connstr .= ' port=' . $port; } if ($database = $this->config['database']) { $connstr .= ' dbname=\'' . addslashes($database) . '\''; } if ($user = $this->config['user']) { $connstr .= ' user=\'' . addslashes($user) . '\''; } if ($password = $this->config['password']) { $connstr .= ' password=\'' . addslashes($password) . '\''; } if ($persistent) { $conn = @pg_pconnect($connstr); } else { $conn = @pg_connect($connstr); } if (!is_resource($conn)) { $this->_raiseError($php_errormsg); } if (isset($this->config['charset']) && ($charset = $this->config['charset'])) { pg_set_client_encoding($conn, $charset); } $this->connectionId = $conn; }