Esempio n. 1
0
 public static function getInstance()
 {
     if (DBConnection::$instance == null) {
         DBConnection::$instance = new DBConnection();
     }
     return DBConnection::$instance;
 }
Esempio n. 2
0
 public static function getInstance($hostname = 'localhost', $databasename = 'smsempresa', $username = '******', $password = '')
 {
     if (!isset(self::$instance)) {
         self::$instance = new PDO('mysql:host=localhost;dbname=smsempresa', 'root', '');
     }
     return self::$instance;
 }
 public static function getTaskTotal($taskid)
 {
     if (intval($taskid) <= 0) {
         return 0;
     }
     $db = DBConnection::instance();
     return $db->sq("SELECT SUM(minutes) FROM {$db->prefix}time_tracker WHERE task_id = " . intval($taskid));
 }
 /**
  * @static
  * @return DBConnection
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Esempio n. 5
0
 public static function instantiate()
 {
     if (!isset(self::$instance)) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
 public static function getUnreadCount()
 {
     if (!isset($_SESSION['userid'])) {
         return 0;
     }
     $current_user_id = (int) $_SESSION['userid'];
     $db = DBConnection::instance();
     return $db->sq("SELECT COUNT(*) FROM {$db->prefix}notifications WHERE shown != 1 AND user_id = " . $current_user_id);
 }
 public static function get()
 {
     // create the instance if it does not exist
     if (!isset(self::$instance)) {
         // the MYSQL_* constants should be set to or
         //  replaced with your db connection details
         self::$instance = new PDO("mysql:host=localhost;dbname=" . _DNAME, _DUSER, _DPASS);
         if (self::$instance->errorInfo()) {
             throw new Exception('MySQL connection failed');
         }
     }
     // return the instance
     return self::$instance;
 }
/**
 * Show benchmark table
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_benchmark($params, &$smarty)
{
    if (DEBUG < DEBUG_DEVELOPMENT) {
        return '';
    }
    // if
    $benchmark =& BenchmarkTimer::instance();
    $db =& DBConnection::instance();
    $result = array('Executed in: ' . (double) number_format($benchmark->TimeElapsed(), 3) . 's', 'SQL queries: ' . $db->query_counter);
    if (function_exists('memory_get_usage')) {
        $result[] = 'Memory usage: ' . number_format(memory_get_usage() / 1048576, 2, '.', ',') . 'MB';
    }
    // if
    return '<p id="benchmark">' . implode('. ', $result) . '</p>';
}
Esempio n. 9
0
/**
 * Handle on shutdown
 *
 * @param void
 * @return null
 */
function system_handle_on_shutdown()
{
    ProjectObjectViews::save();
    // Lets kill a transaction if we have something open
    $database =& DBConnection::instance();
    if (instance_of($database, 'DBConnection') && $database->transaction_level > 0) {
        $database->rollback();
    }
    // if
    if (DEBUG >= DEBUG_DEVELOPMENT) {
        $logger =& Logger::instance();
        $logger->logToFile(ENVIRONMENT_PATH . '/logs/' . date('Y-m-d') . '.txt');
    }
    // if
}
Esempio n. 10
0
 private function getUserFromDB($username)
 {
     $db = DBConnection::instance();
     $result = $db->dq("SELECT role,id FROM {$db->prefix}users WHERE username = ?", array($username));
     $row = $result->fetch_assoc();
     $return = array();
     $return['id'] = 0;
     // default, empty user id
     $return['role'] = 3;
     // default, readonly
     if ($result && is_array($row) && count($row) > 0) {
         $return['id'] = $row['id'];
         $return['role'] = $row['role'];
     }
     return $return;
 }
Esempio n. 11
0
<?php

/*
	This file is part of myTinyTodo.
	(C) Copyright 2010-2011 Max Pozdeev <*****@*****.**>
	Licensed under the GNU GPL v2+ license. See file COPYRIGHT for details.
*/
require_once 'init.inc';
$db = DBConnection::instance();
$field_id = (int) $_GET['fid'];
$listId = (int) _get('list');
// We can't use have_write_access() because this is a GET request and have_write_access() requires a CSRF token in a POST request.
// Since we're not modifying any data, we don't use a POST request.
$onlyPublishedList = have_access('edit') ? false : true;
$listData = $db->sqa("SELECT * FROM {mytinytodo_lists} WHERE field_id = ? " . ($onlyPublishedList ? "AND published=1" : ""), array($field_id));
if (!$listData) {
    echo 'No such list or access denied';
    drupal_exit();
}
$sqlSort = "ORDER BY compl ASC, ";
if ($listData['sorting'] == 1) {
    $sqlSort .= "prio DESC, ddn ASC, duedate ASC, ow ASC";
} elseif ($listData['sorting'] == 2) {
    $sqlSort .= "ddn ASC, duedate ASC, prio DESC, ow ASC";
} else {
    $sqlSort .= "ow ASC";
}
$data = array();
$q = $db->dq("SELECT *, duedate IS NULL AS ddn FROM {mytinytodo_todos} WHERE list_id = ? {$sqlSort}", array($listId));
while ($r = $q->fetch_assoc($q)) {
    $data[] = $r;
Esempio n. 12
0
 public static function instance()
 {
     if (!isset(self::$instance)) {
         //$c = __CLASS__;
         $c = 'DBConnection';
         self::$instance = new $c();
     }
     return self::$instance;
 }
 /**
  * @static
  * @param $type
  * @param array $value
  * @return array
  * @throws Exception
  */
 public static function findByListenerTypeAndValue($type, $value = null)
 {
     if ($type !== NotificationListener::LISTENER_TYPE_GLOBAL && empty($value)) {
         throw new Exception('Can not find non-global listener (' . $type . ') without a list or task id (' . $value . ')');
     }
     $return = array();
     $db = DBConnection::instance();
     if ($type === NotificationListener::LISTENER_TYPE_GLOBAL) {
         $result = $db->dq("SELECT * FROM {$db->prefix}notification_listeners WHERE type = 'global'");
     } else {
         $result = $db->dq("SELECT * FROM {$db->prefix}notification_listeners WHERE type = ? AND value = ?", array($type, $value));
     }
     while ($row = $result->fetch_assoc()) {
         $item = new NotificationListener();
         $item->setType($row['type']);
         $item->setUserid($row['user_id']);
         if ($type !== NotificationListener::LISTENER_TYPE_GLOBAL) {
             $item->setValue($row['value']);
         }
         $return[] = $item;
     }
     return $return;
 }
Esempio n. 14
0
function getUserName($userid)
{
    $db = DBConnection::instance();
    $username = '';
    if ($userid > 0) {
        $username = $db->sq("SELECT username FROM {$db->prefix}users WHERE id={$userid}");
    }
    return $username;
}
Esempio n. 15
0
 /**
  * Get DB Connection Instance
  *
  * The DBConnection class is a singleton.  You may only construct one
  * DBConnection object and it must be done by calling this static method.
  *
  * @return DBConnection DBConnection instance
  */
 public static function getDBConnection()
 {
     if (self::$instance == null) {
         self::$instance = new DBConnection();
     }
     return self::$instance;
 }
Esempio n. 16
0
/**
 * Get MySQL server variable value
 *
 * @param string $variable_name
 * @return mixed
 */
function db_get_variable_value($variable_name)
{
    $connection =& DBConnection::instance();
    return $connection->getVariableValue($variable_name);
}
 /**
  * Construct upgrade utility
  *
  * @param void
  * @return UpgradeUtility
  */
 function __construct()
 {
     $charset = defined('DB_CHARSET') && DB_CHARSET ? DB_CHARSET : null;
     $this->db =& DBConnection::instance();
     $this->db->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, true, $charset);
 }
Esempio n. 18
0
function getUserListsSimple()
{
    $db = DBConnection::instance();
    $a = array();
    $field_id = (int) $_GET['fid'];
    $q = $db->dq("SELECT id, name FROM {mytinytodo_lists} WHERE field_id = ? ORDER BY id ASC", array($field_id));
    while ($r = $q->fetch_row()) {
        $a[$r[0]] = $r[1];
    }
    return $a;
}
Esempio n. 19
0
 public static function getConnection()
 {
     if (empty(self::$instance)) {
         self::$instance = new DBConnection();
     }
     return self::$instance;
 }
Esempio n. 20
0
function getUserListsSimple()
{
    $db = DBConnection::instance();
    $a = array();
    $q = $db->dq("SELECT id,name FROM {$db->prefix}lists ORDER BY id ASC");
    while ($r = $q->fetch_row()) {
        $a[$r[0]] = $r[1];
    }
    return $a;
}
 /**
  * Start upgrade by creating backup
  *
  * @param void
  * @return null
  */
 function startUpgrade()
 {
     $work_path = ENVIRONMENT_PATH . '/work';
     if (is_dir($work_path)) {
         if (is_writable($work_path)) {
             $connection =& DBConnection::instance();
             $tables = $connection->listTables(TABLE_PREFIX);
             if (is_foreachable($tables)) {
                 $dump = $connection->dumpTables($tables, $work_path . '/database-backup-' . date('Y-m-d-H-i-s') . '.sql', true, true);
                 if ($dump && !is_error($dump)) {
                     return true;
                 } else {
                     return is_error($dump) ? $dump->getMessage() : 'Failed to back up database content';
                 }
                 // if
             } else {
                 return 'There are no activeCollab tables in the database';
             }
             // if
         } else {
             return "Work folder not writable";
         }
         // if
     } else {
         return "Work folder not found. Expected location: {$work_path}";
     }
     // if
 }