本文整理汇总了PHP中core\Database::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::getInstance方法的具体用法?PHP Database::getInstance怎么用?PHP Database::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core\Database
的用法示例。
在下文中一共展示了Database::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInviteById
public static function getInviteById($id)
{
$statement = DB::getInstance()->prepare("SELECT * FROM invite WHERE `id`=? LIMIT 0,1");
$statement->bindValue(1, $id, DB::PARAM_STR);
$statement->execute();
return $statement->fetchObject(__CLASS__);
}
示例2: getUserId
public static function getUserId($username, $password)
{
$result = Database::getInstance()->prepare("SELECT id FROM `users` where `username` = :username AND `password`=:password OR `email`=:username AND `password`=:password");
$result->execute(array(':username' => $username, ':password' => $password));
$row = $result->fetch(PDO::FETCH_ASSOC);
return $row['id'];
}
示例3: init
public static function init()
{
$stn = DB::getInstance()->prepare("SELECT k, v FROM options");
$stn->execute();
$opt = $stn->fetchAll(DB::FETCH_UNIQUE | DB::FETCH_COLUMN);
// $GLOBALS['OPTIONS'] = $opt;
self::$list = $opt;
return $opt;
}
示例4: __construct
/**
* Create a new PageData object.
* @param string $tableName Target table name
* @param string $extras Such as where statement or order statement
* @param array $column Column names needs to be fetch
*/
public function __construct($tableName, $extras = '', $column = array('*'))
{
$columns = '`' . implode('`, `', $column) . '`';
$this->countQuery = Database::getInstance()->prepare("SELECT COUNT(*) FROM `{$tableName}` {$extras}");
$this->query = Database::getInstance()->prepare("SELECT {$columns} FROM `{$tableName}` {$extras} LIMIT :pageDataStart,:pageDataRPP");
if ($_GET['page']) {
$this->setPage($_GET['page']);
}
}
示例5: save
public function save($mode = self::SAVE_AUTO)
{
$map = array();
$reflection = new ReflectionObject($this);
$reflectionProp = $reflection->getProperties(ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PUBLIC);
foreach ($reflectionProp as $property) {
if (strpos($property->getDocComment(), '@ignore')) {
continue;
}
$propertyName = $property->getName();
if ($propertyName == 'primaryKey') {
continue;
}
if ($property->isProtected()) {
$property->setAccessible(true);
}
$propertyValue = $property->getValue($this);
$map[$propertyName] = $propertyValue;
}
$primaryKey = $this->getPrimaryKeyName($reflection);
$identifier = $map[$primaryKey];
unset($map[$primaryKey]);
$tableName = $this->getTableName($reflection);
if ($mode == self::SAVE_UPDATE || $identifier && $mode != self::SAVE_INSERT) {
$sql = "UPDATE `{$tableName}` SET ";
foreach ($map as $key => $value) {
$sql .= "`{$key}` = :{$key},";
}
$sql = rtrim($sql, ',');
$sql .= " WHERE {$primaryKey} = :id";
$statement = Database::getInstance()->prepare($sql);
$statement->bindValue(':id', $identifier);
foreach ($map as $key => $value) {
$statement->bindValue(":{$key}", $value);
}
} else {
$sql = "INSERT INTO `{$tableName}` SET ";
foreach ($map as $key => $value) {
$sql .= "`{$key}` = :{$key},";
}
$sql = rtrim($sql, ',');
$statement = Database::getInstance()->prepare($sql);
foreach ($map as $key => $value) {
$statement->bindValue(":{$key}", $value);
}
}
$statement->execute();
if (!$identifier) {
$insertId = Database::getInstance()->lastInsertId();
if ($insertId) {
$reflection->getProperty($primaryKey)->setValue($this, $insertId);
}
}
}
示例6: execute
/**
* Migrate current database
* @param $dropTable bool drop the table
*/
public function execute($dropTable = false)
{
$this->database = Database::getInstance();
$modelDir = "Application/Model";
$file = opendir($modelDir);
// there is fileName
while (($fileName = readdir($file)) !== false) {
if (substr($fileName, -4) == ".php") {
$this->migrateTable($modelDir . "/" . $fileName, $dropTable);
}
}
}
示例7: setNextRun
public static function setNextRun($cronId, $step)
{
$inTransaction = DB::getInstance()->inTransaction();
if (!$inTransaction) {
DB::getInstance()->beginTransaction();
}
$st = DB::sql("UPDATE cron SET nextrun=? WHERE id=?");
$st->bindValue(1, $step, DB::PARAM_INT);
$st->bindValue(2, $cronId, DB::PARAM_STR);
$st->execute();
if (!$inTransaction) {
DB::getInstance()->commit();
}
}
示例8: destroy
public function destroy()
{
$inTransaction = DB::getInstance()->inTransaction();
if (!$inTransaction) {
DB::getInstance()->beginTransaction();
}
$st = DB::sql("UPDATE card SET status=0 WHERE card=:card");
// 失效卡
$st->bindValue(":card", $this->card, DB::PARAM_STR);
$flag = $st->execute();
if (!$inTransaction) {
DB::getInstance()->commit();
}
return $flag;
}
示例9: execute
/**
* Execute a PDO prepare with execute
*
* @param $query
* The query to execute
* @param array $params
* The query parameters
* @return An array with the results
*/
public static function execute($query, $params = [])
{
// Preparing the query with the database instance
$results = Database::getInstance()->prepare($query);
// Executing the query with the given parameters
$results->execute($params);
// Fetching the results
$results = $results->fetchAll(\PDO::FETCH_OBJ);
// Checking them
if (count($results) < 2) {
$results = current($results);
}
// Returning them
return $results;
}
示例10: run
public function run()
{
$resetDate = '1';
$date = date("d", time());
if ($date == $resetDate) {
$inTransaction = DB::getInstance()->inTransaction();
if (!$inTransaction) {
DB::getInstance()->beginTransaction();
}
$st = DB::sql("UPDATE member SET flow_up=0, flow_down=0 WHERE `enable`=1 AND `plan`!='Z'");
$st->execute();
if (!$inTransaction) {
DB::getInstance()->commit();
}
}
return false;
}
示例11: insert
public function insert()
{
$reflection = new ReflectionObject($this);
$map = $this->getTableMap($reflection);
$primaryKey = $this->getPrimaryKeyName($reflection);
$tableName = $this->getTableName($reflection);
$sql = "INSERT INTO `{$tableName}` SET ";
foreach ($map as $key => $value) {
$sql .= "`{$key}` = :{$key},";
}
$sql = rtrim($sql, ',');
$statement = Database::getInstance()->prepare($sql);
foreach ($map as $key => $value) {
$statement->bindValue(":{$key}", $value);
}
$statement->execute();
$insertId = Database::getInstance()->lastInsertId();
if ($insertId) {
$reflection->getProperty($primaryKey)->setValue($this, $insertId);
}
}
示例12: loadTemplate
<?php
session_start();
spl_autoload_register(function ($class) {
$classPath = str_replace("\\", "/", $class);
require_once $classPath . '.php';
});
require_once 'core/App.php';
\Core\Database::SetInstance(\Config\DatabaseConfig::DB_INSTANCE, \Config\DatabaseConfig::DB_DRIVER, \Config\DatabaseConfig::DB_USER, \Config\DatabaseConfig::DB_PASS, \Config\DatabaseConfig::DB_NAME, \Config\DatabaseConfig::DB_HOST);
$app = new \Core\App(\Core\Database::getInstance(\Config\DatabaseConfig::DB_INSTANCE));
function loadTemplate($templateName, $data = null)
{
require_once 'templates/' . $templateName . '.php';
}
示例13: deleteNode
/**
* Delete node
* @param $nodeId
* @return bool
*/
public static function deleteNode($nodeId)
{
$inTransaction = DB::getInstance()->inTransaction();
if (!$inTransaction) {
DB::getInstance()->beginTransaction();
}
$statement = DB::getInstance()->prepare("DELETE FROM node WHERE id=:id");
$statement->bindValue(':id', $nodeId, DB::PARAM_INT);
$result = $statement->execute();
if (!$inTransaction) {
DB::getInstance()->commit();
}
return $result;
}
示例14: pagination
/**
* @return UserCollection
* @throws \Exception
*/
public function pagination($pageNum, $count)
{
$param1 = (int) $pageNum;
$param2 = (int) $count;
$this->placeholders[] = $pageNum;
$this->placeholders[] = $count;
$db = Database::getInstance('app');
$this->query = "SELECT * FROM user" . $this->where . " ORDER BY createdAt DESC LIMIT {$param1},{$count};";
$result = $db->prepare($this->query);
$result->execute($this->placeholders);
$collection = [];
foreach ($result->fetchAll() as $entityInfo) {
$entity = new User($entityInfo['username'], $entityInfo['password'], $entityInfo['registerDate'], $entityInfo['emailVerified'], $entityInfo['email'], $entityInfo['createdAt'], $entityInfo['updatedAt'], $entityInfo['id']);
$collection[] = $entity;
self::$selectedObjectPool[] = $entity;
}
return new UserCollection($collection);
}
示例15: pagination
/**
* @return SdfCollection
* @throws \Exception
*/
public function pagination($pageNum, $count)
{
$param1 = (int) $pageNum;
$param2 = (int) $count;
$this->placeholders[] = $pageNum;
$this->placeholders[] = $count;
$db = Database::getInstance('app');
$this->query = "SELECT * FROM sdf" . $this->where . " ORDER BY createdAt DESC LIMIT {$param1},{$count};";
$result = $db->prepare($this->query);
$result->execute($this->placeholders);
$collection = [];
foreach ($result->fetchAll() as $entityInfo) {
$entity = new Sdf($entityInfo['id']);
$collection[] = $entity;
self::$selectedObjectPool[] = $entity;
}
return new SdfCollection($collection);
}