xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / db.inc.php (3a54b7bef1998f1246bd324ee3e0f138aabeca90) (1,374B) (mode 100644) [raw]
<?php
require_once($INC . "/xlog.inc.php");

$sql_debug = 0;

$sql_error = "";

/*
 * Set error string
 */
function sql_set_error($str)
{
	global $sql_error;

	$sql_error = $str;
}

function sql_error()
{
	global $sql_error;

	return $sql_error;
}

/*
 * Connect to database
 */
function sql_open($str)
{
	global $sql_debug;

	if ($sql_debug > 0)
		xlog("DB: opening [$str]...");

	if (strncmp($str, "sqlite:", 7) != 0) {
		sql_set_error("$str connect string not supported");
		return FALSE;
	}

	$file = substr($str, 7);

	$db = new SQLite3($file);
	if ($db === FALSE) {
		sql_set_error("Cannot connect to database $file: " . $db->lastErrorMsg());
		return FALSE;
	}

	return $db;
}

/*
 * Escaping
 */
function sql_escape($db, $str)
{
	return $db->escapeString($str);
}

/*
 * Do a query
 */
function sql_query($db, $sql)
{
	global $sql_debug;

	if ($sql_debug > 0)
		xlog("DB: running [$sql]...");

	$res = $db->query($sql);
	if ($res === FALSE) {
		sql_set_error("$sql: " . $db->lastErrorMsg());
		return FALSE;
	}

	return $res;
}

/*
 * Close database
 */
function sql_close($db)
{
	$db->close();
}

/*
 * Free results
 */
function sql_free_result($res)
{
	$res->finalize();
}

/*
 * Returns a row as an associated array
 */
function sql_fetch_array($res)
{
	return $res->fetchArray(SQLITE3_ASSOC);
}

function sql_last_id($db)
{
	return $db->lastInsertRowID();
}

?>
Hints

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