From 82d40e32363c4e96996eca7ee44ade879589aa0e Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Sun, 26 Apr 2020 16:33:36 +0200 Subject: Expand tabs and remove trailing whitespace --- ratatoeskr/sys/db.php | 150 +++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) (limited to 'ratatoeskr/sys/db.php') diff --git a/ratatoeskr/sys/db.php b/ratatoeskr/sys/db.php index 36d5348..d122502 100644 --- a/ratatoeskr/sys/db.php +++ b/ratatoeskr/sys/db.php @@ -1,9 +1,9 @@ 'SET NAMES utf8', - )); - $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + global $config; + global $db_con; + + $db_con = new PDO( + "mysql:host=" . $config["mysql"]["server"] . ";dbname=" . $config["mysql"]["db"] . ";charset=utf8", + $config["mysql"]["user"], + $config["mysql"]["passwd"], + array( + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', + )); + $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } /* @@ -44,95 +44,95 @@ function db_connect() */ function sub_prefix($q) { - global $config; - return str_replace("PREFIX_", $config["mysql"]["prefix"], $q); + global $config; + return str_replace("PREFIX_", $config["mysql"]["prefix"], $q); } /* * Function: prep_stmt - * + * * Prepares a SQL statement using the global DB connection. * This will also replace "PREFIX_" with the prefix defined in 'config.php'. - * + * * Parameters: - * $q - The query / statement to prepare. - * + * $q - The query / statement to prepare. + * * Returns: - * A PDOStatement object. + * A PDOStatement object. */ function prep_stmt($q) { - global $db_con; - - return $db_con->prepare(sub_prefix($q)); + global $db_con; + + return $db_con->prepare(sub_prefix($q)); } /* * Function: qdb - * + * * Prepares statement (1st argument) with and executes it with the remaining arguments. - * + * * Returns: - * A PDOStatement object. + * A PDOStatement object. */ function qdb() { - $args = func_get_args(); - if(count($args) < 1) - throw new InvalidArgumentException("qdb needs at least 1 argument"); - - $stmt = prep_stmt($args[0]); - $stmt->execute(array_slice($args, 1)); - return $stmt; + $args = func_get_args(); + if(count($args) < 1) + throw new InvalidArgumentException("qdb needs at least 1 argument"); + + $stmt = prep_stmt($args[0]); + $stmt->execute(array_slice($args, 1)); + return $stmt; } /* * Class: Transaction - * + * * Makes using transactions easier. */ class Transaction { - public $startedhere; - - /* - * Constructor: __construct - * - * Start a new transaction. - */ - public function __construct() - { - global $db_con; - $this->startedhere = !($db_con->inTransaction()); - if($this->startedhere) - $db_con->beginTransaction(); - } - - /* - * Function: commit - * - * Commit the transaction. - */ - public function commit() - { - global $db_con; - - if($this->startedhere) - $db_con->commit(); - } - - /* - * Function: rollback - * - * Toll the transaction back. - */ - public function rollback() - { - global $db_con; - - if($this->startedhere) - $db_con->rollBack(); - } + public $startedhere; + + /* + * Constructor: __construct + * + * Start a new transaction. + */ + public function __construct() + { + global $db_con; + $this->startedhere = !($db_con->inTransaction()); + if($this->startedhere) + $db_con->beginTransaction(); + } + + /* + * Function: commit + * + * Commit the transaction. + */ + public function commit() + { + global $db_con; + + if($this->startedhere) + $db_con->commit(); + } + + /* + * Function: rollback + * + * Toll the transaction back. + */ + public function rollback() + { + global $db_con; + + if($this->startedhere) + $db_con->rollBack(); + } } ?> -- cgit v1.2.3-70-g09d2