当前位置: 首页>>代码示例>>PHP>>正文


PHP Database::getInstance方法代码示例

本文整理汇总了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__);
 }
开发者ID:sendya,项目名称:shadowsocks-panel,代码行数:7,代码来源:Invite.php

示例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'];
 }
开发者ID:saqbest,项目名称:test_project,代码行数:7,代码来源:App.php

示例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;
 }
开发者ID:sendya,项目名称:shadowsocks-panel,代码行数:9,代码来源:Option.php

示例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']);
     }
 }
开发者ID:sendya,项目名称:mcSkin,代码行数:15,代码来源:PageData.php

示例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);
         }
     }
 }
开发者ID:sendya,项目名称:mcSkin,代码行数:54,代码来源:Model.php

示例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);
         }
     }
 }
开发者ID:phuongjolly,项目名称:ECard,代码行数:16,代码来源:Migration.php

示例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();
     }
 }
开发者ID:sendya,项目名称:shadowsocks-panel,代码行数:14,代码来源:Cron.php

示例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;
 }
开发者ID:sendya,项目名称:shadowsocks-panel,代码行数:15,代码来源:Card.php

示例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;
 }
开发者ID:Halvra,项目名称:OpenAuth-Server,代码行数:24,代码来源:Queries.php

示例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;
 }
开发者ID:sendya,项目名称:shadowsocks-panel,代码行数:17,代码来源:ClearTransfer.php

示例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);
     }
 }
开发者ID:kingstarhe,项目名称:KK-Framework,代码行数:21,代码来源:Model.php

示例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';
}
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:14,代码来源:index.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;
 }
开发者ID:sendya,项目名称:shadowsocks-panel,代码行数:19,代码来源:Node.php

示例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);
 }
开发者ID:zhivkokasabov,项目名称:algaivel,代码行数:22,代码来源:UserRepository.php

示例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);
 }
开发者ID:zhivkokasabov,项目名称:algaivel,代码行数:22,代码来源:SdfRepository.php


注:本文中的core\Database::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。