<?php
require_once($INC . "/log.inc.php");
$rg_sql_error = "";
if (!function_exists("pg_connect"))
die("FATAL: php PostgreSQL is not installed!");
/*
* Set error string
*/
function rg_sql_set_error($str)
{
global $rg_sql_error;
rg_log("\tError: $str");
$rg_sql_error = $str;
}
function rg_sql_error()
{
global $rg_sql_error;
return $rg_sql_error;
}
/*
* Connect to database
*/
function rg_sql_open($str)
{
global $rg_sql_debug;
if ($rg_sql_debug > 0)
rg_log("DB: opening [$str]...");
$db = @pg_pconnect($str);
if ($db === FALSE) {
rg_sql_set_error("cannot connect to database (" . $php_errormsg . ")");
return FALSE;
}
return $db;
}
/*
* Escaping
*/
function rg_sql_escape($db, $str)
{
return pg_escape_string($db, $str);
}
/*
* Do a query
*/
function rg_sql_query($db, $sql)
{
global $rg_sql_debug;
if ($rg_sql_debug > 0) {
rg_log("\tDB: running [$sql]...");
$_s = microtime(TRUE);
}
$res = @pg_query($db, $sql);
if ($res === FALSE) {
rg_sql_set_error("$sql: " . @pg_last_error($db));
return FALSE;
}
if ($rg_sql_debug > 0) {
$diff = sprintf("%u", (microtime(TRUE) - $_s) * 1000);
$rows = rg_sql_num_rows($res);
$arows = rg_sql_affected_rows($res);
rg_log("\tDB: Took " . $diff . "ms, $rows row(s), $arows affected");
}
return $res;
}
/*
* Close database
*/
function rg_sql_close($db)
{
pg_close($db);
}
/*
* Free results
*/
function rg_sql_free_result($res)
{
pg_free_result($res);
}
/*
* Returns a row as an associated array
*/
function rg_sql_fetch_array($res)
{
return pg_fetch_assoc($res);
}
function rg_sql_last_id($db)
{
$sql = "SELECT lastval() AS id";
$res = rg_sql_query($db, $sql);
if ($res === FALSE)
return FALSE;
$row = rg_sql_fetch_array($res);
rg_sql_free_result($res);
return $row['id'];
}
function rg_sql_num_rows($res)
{
return pg_num_rows($res);
}
function rg_sql_affected_rows($res)
{
return pg_affected_rows($res);
}
function rg_sql_begin($db)
{
$res = rg_sql_query($db, "BEGIN");
if ($res === FALSE)
return FALSE;
rg_sql_free_result($res);
return TRUE;
}
function rg_sql_commit($db)
{
$res = rg_sql_query($db, "COMMIT");
if ($res === FALSE)
return FALSE;
rg_sql_free_result($res);
return TRUE;
}
?>
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master