self::$dbo = $this;
}
+ /**
+ * @brief Checks if the database object is initialized
+ *
+ * This is a possible bugfix for something that doesn't occur for me.
+ * There seems to be situations, where the object isn't initialized.
+ */
+ private static function initialize() {
+ if (!is_object(self::$dbo)) {
+ global $db;
+ self::$dbo = $db;
+ }
+ }
+
/**
* @brief Returns the MySQL server version string
*
* @return object statement object
*/
public static function p($sql) {
+ self::initialize();
+
$a = get_app();
$stamp1 = microtime(true);
* @return boolean Was the query successfull? False is returned only if an error occurred
*/
public static function e($sql) {
+ self::initialize();
+
$a = get_app();
$stamp = microtime(true);
* @return boolean Are there rows for that condition?
*/
public static function exists($table, $condition) {
+ self::initialize();
+
if (empty($table)) {
return false;
}
* @return array first row of query
*/
public static function fetch_first($sql) {
+ self::initialize();
+
$params = self::getParam(func_get_args());
$stmt = self::p($sql, $params);
* @return int Number of rows
*/
public static function affected_rows() {
+ self::initialize();
+
return self::$dbo->affected_rows;
}
* @return int Number of columns
*/
public static function columnCount($stmt) {
+ self::initialize();
+
if (!is_object($stmt)) {
return 0;
}
* @return int Number of rows
*/
public static function num_rows($stmt) {
+ self::initialize();
+
if (!is_object($stmt)) {
return 0;
}
* @return array current row
*/
public static function fetch($stmt) {
+ self::initialize();
+
if (!is_object($stmt)) {
return false;
}
* @return boolean was the insert successfull?
*/
public static function insert($table, $param, $on_duplicate_update = false) {
+ self::initialize();
+
$sql = "INSERT INTO `".self::$dbo->escape($table)."` (`".implode("`, `", array_keys($param))."`) VALUES (".
substr(str_repeat("?, ", count($param)), 0, -2).")";
* @return integer Last inserted id
*/
public static function lastInsertId() {
+ self::initialize();
+
switch (self::$dbo->driver) {
case 'pdo':
$id = self::$dbo->db->lastInsertId();
* @return boolean was the lock successful?
*/
public static function lock($table) {
+ self::initialize();
+
// See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
self::e("SET autocommit=0");
$success = self::e("LOCK TABLES `".self::$dbo->escape($table)."` WRITE");
* @return boolean was the unlock successful?
*/
public static function unlock() {
+ self::initialize();
+
// See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
self::e("COMMIT");
$success = self::e("UNLOCK TABLES");
* @return boolean Was the command executed successfully?
*/
public static function transaction() {
+ self::initialize();
+
if (!self::e('COMMIT')) {
return false;
}
* @return boolean Was the command executed successfully?
*/
public static function commit() {
+ self::initialize();
+
if (!self::e('COMMIT')) {
return false;
}
* @return boolean Was the command executed successfully?
*/
public static function rollback() {
+ self::initialize();
+
if (!self::e('ROLLBACK')) {
return false;
}
* @return boolean|array was the delete successfull? When $in_process is set: deletion data
*/
public static function delete($table, $param, $in_process = false, &$callstack = array()) {
+ self::initialize();
$commands = array();
* @return boolean was the update successfull?
*/
public static function update($table, $fields, $condition, $old_fields = array()) {
+ self::initialize();
$table = self::$dbo->escape($table);
* $data = dba::select($table, $fields, $condition, $params);
*/
public static function select($table, $fields = array(), $condition = array(), $params = array()) {
+ self::initialize();
+
if ($table == '') {
return false;
}
* @return array Data array
*/
public static function inArray($stmt, $do_close = true) {
+ self::initialize();
+
if (is_bool($stmt)) {
return $stmt;
}
* @return string Error number (0 if no error)
*/
public static function errorNo() {
+ self::initialize();
+
return self::$dbo->errorno;
}
* @return string Error message ('' if no error)
*/
public static function errorMessage() {
+ self::initialize();
+
return self::$dbo->error;
}
* @return boolean was the close successfull?
*/
public static function close($stmt) {
+ self::initialize();
+
if (!is_object($stmt)) {
return false;
}