本文整理汇总了PHP中DBConnection::db方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnection::db方法的具体用法?PHP DBConnection::db怎么用?PHP DBConnection::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection::db方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
static function connect()
{
self::$db = new mysqli(Conf::$DB_HOST, Conf::$DB_USER, Conf::$DB_PASSWORD, Conf::$DB_SELECT, Conf::$DB_PORT);
if (self::$db->connect_errno) {
die('Erreur de connexion (' . self::$db->connect_errno . ') ' . self::$db->connect_error);
}
}
示例2: __construct
public function __construct()
{
$this->db = DBConnection::db();
$this->updateWorkspaceStmt = $this->db->prepare("UPDATE workspaces_v2 " . "SET name= :name, content= :content " . "WHERE user_id= :user AND id= :id; ");
$this->insertWorkspaceStmt = $this->db->prepare("INSERT INTO workspaces_v2 (id, id_v1, user_id, name, content) " . "VALUES (:id, NULL, :user, :name, :content); ");
$this->getWorkspacesStmt = $this->db->prepare("SELECT id, id_v1, user_id, name, content " . "FROM workspaces_v2 " . "WHERE (user_id = :user AND (name LIKE :qname OR id LIKE :qid)) " . "ORDER BY name; ");
$this->getWorkspaceByIdStmt = $this->db->prepare("SELECT id, id_v1, user_id, name, content " . "FROM workspaces_v2 " . "WHERE (user_id = :user AND (name LIKE :qname OR id LIKE :qid)) OR (id = :id OR id_v1 = :idv1); ");
$this->deleteWorkspaceStmt = $this->db->prepare("DELETE FROM workspaces_v2 WHERE id= :id AND user_id= :user; ");
}
示例3: db
public static function db()
{
if (DBConnection::$db != null) {
return DBConnection::$db;
}
$server = DB_HOST;
$username = DB_USER;
$password = DB_PASSWD;
$dbname = DB_NAME;
try {
// Open a persistent database connection, for performance improvement
DBConnection::$db = new PDO('mysql:host=' . $server . ';dbname=' . $dbname . ';charset=utf8', $username, $password, array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (Exception $e) {
echo 'caughtL ', $e->getMessage(), '\\n';
}
return DBConnection::$db;
}
示例4: retrieveCustomer
public static function retrieveCustomer($consumerKey)
{
$db = DBConnection::db();
$statement = $db->prepare('SELECT `consumer_secret` FROM `api_clients` WHERE `active` = TRUE AND `consumer_key` = :consumer_key LIMIT 1');
$statement->bindParam(':consumer_key', $consumerKey, PDO::PARAM_STR);
$exe = $statement->execute();
if (!$exe || $exe == false || $statement->rowCount() != 1) {
// Looks like it's a no
return false;
} else {
// Fetch the info
$row = $statement->fetch(PDO::FETCH_ASSOC);
if (!$row) {
return false;
}
return $row['consumer_secret'];
}
}
示例5: getOrInsertUser
public function getOrInsertUser($oauth_uid, $oauth_provider, $user_data)
{
$db = DBConnection::db();
$result = $this->getUser($oauth_uid, $oauth_provider);
if ($result != null) {
return $result;
}
$joined_keys = '(`oauth_uid`, `oauth_provider`, `' . implode('`, `', array_keys($user_data)) . '`)';
$joined_values = "('{$oauth_uid}', '{$oauth_provider}'";
foreach ($user_data as $v) {
$joined_values .= ', ';
$joined_values .= $v === null ? 'NULL' : "'{$v}'";
}
$joined_values .= ')';
$insert = "INSERT INTO users {$joined_keys} VALUES {$joined_values}";
print_r($insert);
$db->exec($insert);
return $this->getUser($oauth_uid, $oauth_provider);
}
示例6: logSearchQuery
public static function logSearchQuery($searchQuery, $from = "site")
{
$db = DBConnection::db();
if (!isset($_SERVER["HTTP_REFERER"])) {
$_SERVER["HTTP_REFERER"] = "";
}
$query = "INSERT INTO `stats_search_query` (query, referer, origin, date)";
$query .= " VALUES(:search_query, :referer, :from, NOW());";
$statement = $db->prepare($query);
$statement->bindParam(':search_query', trim($searchQuery), PDO::PARAM_STR);
$statement->bindParam(':referer', $_SERVER["HTTP_REFERER"], PDO::PARAM_STR);
$statement->bindParam(':from', $from, PDO::PARAM_STR);
// Executes the query
$exe = $statement->execute();
// Returns true if the query was well executed and returned a single line
if ($exe && $statement->rowCount() == 1) {
return true;
} else {
return false;
}
}
示例7: DBConnection
{
if (self::$_instance !== null || is_null($config)) {
//We have already stored the object locally so just return it.
//This is how the object always stays the same
return self::$_instance;
}
new DBConnection($config);
//Set the instance.
return self::$_instance;
}
public static function error()
{
if (self::$failSilently == true) {
return false;
}
// If we were called from a post request in ajax, we should just echo the error uri
if (self::$parentCalledFromPost == true) {
echo _SITE_BASE_URL . 'woops';
} else {
// Else : standard header:Location
header('Location: /woops');
}
}
}
/* *************************************************** */
/* */
/* FIRST CONNECTION ROUTINE */
/* */
/* *************************************************** */
$db = DBConnection::db(array('hostname' => "localhost", 'username' => $user, 'password' => $password, 'database' => $database, 'failSilently' => !isset($failSilently) ? false : $failSilently, 'parentCalledFromPost' => !isset($parentCalledFromPost) ? false : $parentCalledFromPost));
示例8: addAPick
public static function addAPick($id)
{
$db = DBConnection::db();
// Latest first
$query = "SELECT id, name, album, artist, image FROM `items` WHERE id=:id AND type=" . _TABLE_TRACK . " LIMIT 1";
$statement = $db->prepare($query);
$statement->bindParam(':id', $id, PDO::PARAM_INT);
// Executes the query
$exe = $statement->execute();
if (!$exe || $exe == false) {
return false;
} else {
// Fetch the info
$row = $statement->fetchAll(PDO::FETCH_ASSOC);
$queryDate = "SELECT MAX(date) AS maxDate FROM `picks`";
$statementDate = $db->prepare($queryDate);
// Executes the query
$exeDate = $statementDate->execute();
if (!$exeDate || $exeDate == false) {
return false;
} else {
$rowDate = $statementDate->fetch(PDO::FETCH_ASSOC);
$maxDate = strftime("%Y-%m-%d", strtotime($rowDate['maxDate'] . " + 1 day"));
}
$queryPick = "INSERT INTO `picks` (name, artist, album, image, link, date) VALUES(:name, :artist, :album, :image, :link, :max_date)";
$statementPick = $db->prepare($queryPick);
$statementPick->bindParam(':name', $row["name"], PDO::PARAM_STR);
$statementPick->bindParam(':artist', $row["artist"], PDO::PARAM_STR);
$statementPick->bindParam(':album', $row["album"], PDO::PARAM_STR);
$statementPick->bindParam(':image', $row["image"], PDO::PARAM_STR);
$statementPick->bindParam(':link', _SITE_URL . '/t/' . DBUtils::toUid($row["id"], _BASE_MULTIPLIER), PDO::PARAM_STR);
$statementPick->bindParam(':max_date', $maxDate, PDO::PARAM_STR);
// Executes the query
$exePick = $statementPick->execute();
if (!$exePick || $exePick == false) {
return false;
} else {
return true;
}
}
}
示例9: checkDatabase
public function checkDatabase()
{
$db = DBConnection::db();
if (!$db) {
$this->log("DB Connection as '{$user}'", false, "Error connecting to database : " . $db->errorInfo());
} else {
if ($this->verbose) {
$this->log("DB Connection as '" . $this->data['user'] . "'", true, "");
}
$statement = $db->prepare("SELECT * FROM items LIMIT 1");
$exe = $statement->execute();
if (!$exe || $exe == false) {
$this->log("DB Query", false, "Error ");
} else {
if ($this->verbose) {
$error = $db->errorInfo();
$this->log("DB Query", true, "Error making query : " . $error[2]);
}
}
}
}
示例10: setDB
/**
* Sets the DB with a database object
* (MUST BE MYSQLI FOR NOW)
*
* (Your application must establish a connection on its own... then pass here)
*
* @param $db MYSQLI database object
*/
public static function setDB($db)
{
self::$db = $db;
}
示例11: header
<?php
require '../../config.php';
$parentCalledFromPost = true;
require _PATH . 'include/database/DBUtils.class.php';
require _PATH . 'include/database/DBConnection.class.php';
$db = DBConnection::db();
// What type of share is it ?
if (isset($_REQUEST['itemType'])) {
if ($_REQUEST['itemType'] == _TABLE_TRACK) {
$itemType = _TABLE_TRACK;
$shortCode = '/t/';
} else {
if ($_REQUEST['itemType'] == _TABLE_ALBUM) {
$itemType = _TABLE_ALBUM;
$shortCode = '/a/';
} else {
header('Location: ' . _SITE_URL);
die(0);
}
}
} else {
header('Location: ' . _SITE_URL);
die(0);
}
// We check we have some info
if ((!isset($_REQUEST['name']) || $_REQUEST['name'] == "") && $itemType == 'track' || (!isset($_REQUEST['album']) || $_REQUEST['album'] == "") && $itemType == 'album' || !isset($_REQUEST['artist']) || $_REQUEST['artist'] == "") {
header('Location: ' . _SITE_URL);
die(0);
}
$name = trim(html_entity_decode($_REQUEST['name'], ENT_COMPAT, "UTF-8"));