aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys/db.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-04-26 16:33:36 +0200
committerLaria Carolin Chabowski <laria@laria.me>2020-04-26 16:33:36 +0200
commit82d40e32363c4e96996eca7ee44ade879589aa0e (patch)
tree44c819d2472697de1e8eb404148f4a087109b27e /ratatoeskr/sys/db.php
parent11c7214cb58be4100422b8f905bc629a8906e6ff (diff)
downloadratatoeskr-cms-82d40e32363c4e96996eca7ee44ade879589aa0e.tar.gz
ratatoeskr-cms-82d40e32363c4e96996eca7ee44ade879589aa0e.tar.bz2
ratatoeskr-cms-82d40e32363c4e96996eca7ee44ade879589aa0e.zip
Expand tabs and remove trailing whitespace
Diffstat (limited to 'ratatoeskr/sys/db.php')
-rw-r--r--ratatoeskr/sys/db.php150
1 files changed, 75 insertions, 75 deletions
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 @@
<?php
/*
* File: ratatoeskr/sys/db.php
- *
+ *
* Helper functions for dealing with MySQL.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -11,7 +11,7 @@
*/
if(!defined("SETUP"))
- require_once(dirname(__FILE__) . "/../config.php");
+ require_once(dirname(__FILE__) . "/../config.php");
require_once(dirname(__FILE__) . "/utils.php");
@@ -24,17 +24,17 @@ $db_con = Null;
*/
function db_connect()
{
- 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);
+ 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 <prep_stmt> 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();
+ }
}
?>