本文整理汇总了PHP中DBConnection::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnection::instance方法的具体用法?PHP DBConnection::instance怎么用?PHP DBConnection::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInstance
public static function getInstance()
{
if (DBConnection::$instance == null) {
DBConnection::$instance = new DBConnection();
}
return DBConnection::$instance;
}
示例2: getInstance
public static function getInstance($hostname = 'localhost', $databasename = 'smsempresa', $username = 'root', $password = '')
{
if (!isset(self::$instance)) {
self::$instance = new PDO('mysql:host=localhost;dbname=smsempresa', 'root', '');
}
return self::$instance;
}
示例3: getTaskTotal
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));
}
示例4: getInstance
/**
* @static
* @return DBConnection
*/
public static function getInstance()
{
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c();
}
return self::$instance;
}
示例5: instantiate
public static function instantiate()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class();
}
return self::$instance;
}
示例6: getUnreadCount
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);
}
示例7: get
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;
}
示例8: smarty_function_benchmark
/**
* 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>';
}
示例9: system_handle_on_shutdown
/**
* 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
}
示例10: getUserFromDB
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;
}
示例11: array
<?php
/*
This file is part of myTinyTodo.
(C) Copyright 2010-2011 Max Pozdeev <maxpozdeev@gmail.com>
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;
示例12: instance
public static function instance()
{
if (!isset(self::$instance)) {
//$c = __CLASS__;
$c = 'DBConnection';
self::$instance = new $c();
}
return self::$instance;
}
示例13: findByListenerTypeAndValue
/**
* @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;
}
示例14: getUserName
function getUserName($userid)
{
$db = DBConnection::instance();
$username = '';
if ($userid > 0) {
$username = $db->sq("SELECT username FROM {$db->prefix}users WHERE id={$userid}");
}
return $username;
}
示例15: getDBConnection
/**
* 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;
}