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


PHP DatabaseFactory::open方法代码示例

本文整理汇总了PHP中DatabaseFactory::open方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseFactory::open方法的具体用法?PHP DatabaseFactory::open怎么用?PHP DatabaseFactory::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseFactory的用法示例。


在下文中一共展示了DatabaseFactory::open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getById

 /**
  * 获取campaign
  * @param int $campaignId
  * @return array
  */
 static function getById($campaignId)
 {
     $redis = RedisFactory::open()->connect($campaignId);
     $key = sprintf(self::$REDIS_KEYS['getById'], $campaignId);
     $result = $redis->get($key)->getResult();
     if ($result === false) {
         // 初始化
         $db = DatabaseFactory::open();
         $result = $db->createCommand("SELECT * FROM g_campaign WHERE id=:id")->findFirst(array(':id' => $campaignId));
         if (empty($result)) {
             $result = array();
         }
         $redis->set($key, $result);
     }
     return $result;
 }
开发者ID:sdgdsffdsfff,项目名称:shfy-giftbag,代码行数:21,代码来源:CampaignService.php

示例2: receivedTotal

    /**
     * 已领取总数(redis重启后,通过command从DB导入到redis)
     * @param int $campaignId
     * @param int $userId
     */
    static function receivedTotal($campaignId, $userId)
    {
        $redis = self::getRedis()->connect($userId);
        $keyReceiveByUserId = sprintf(self::$REDIS_KEYS['receiveByUserId'], $campaignId, $userId);
        $keyReceiveByUserIdIsInit = sprintf(self::$REDIS_KEYS['receiveByUserIdIsInit'], $campaignId, $userId);
        $result = $redis->multi()->scard($keyReceiveByUserId)->get($keyReceiveByUserIdIsInit)->exec()->getResult();
        list($total, $isInit) = $result;
        if ($isInit == false) {
            // 初始化该用户的领取信息
            $db = DatabaseFactory::open();
            $rows = $db->createCommand('
									SELECT giftbagCode FROM g_campaign_mapping_giftbag
									WHERE campaignId=:campaignId AND userId=:userId
							')->findAll(array(':campaignId' => $campaignId, ':userId' => $userId));
            if ($rows) {
                // 同步到领取列表
                foreach ($rows as $row) {
                    $redis->multiChunk('sadd', $keyReceiveByUserId, $row['giftbagCode']);
                }
                $redis->multiChunkFlush();
            }
            // 获取最新的总数
            $result = $redis->multi()->scard($keyReceiveByUserId)->set($keyReceiveByUserIdIsInit, true)->exec()->getResult();
            list($total, $isInit) = $result;
        }
        return $total;
    }
开发者ID:sdgdsffdsfff,项目名称:shfy-giftbag,代码行数:32,代码来源:GiftBagService.php

示例3: add

 /**
  * 新增用户
  * @param array $userData
  * @return int insertId
  */
 static function add($userData)
 {
     $salt = StringUtil::random(10);
     // 初始化
     $db = DatabaseFactory::open();
     $result = $db->createCommand("\n\t\t\tINSERT INTO `g_user` (username,mobile,password,salt)\n\t\t\t\tVALUES (:username,:mobile,:password,:salt)\n\t\t")->execute(array(':username' => $userData['username'], ':mobile' => $userData['mobile'], ':password' => self::encodePassword($userData['password'], $salt), ':salt' => $salt));
     if ($result) {
         $userId = $db->getInsertId();
         $redis = self::getRedis();
         $redis->connect($userId)->del(sprintf(self::$REDIS_KEYS['getById'], $userId));
         $redis->connect($userData['username'])->del(sprintf(self::$REDIS_KEYS['getByUsername'], $userData['username']));
         $redis->connect($userData['mobile'])->del(sprintf(self::$REDIS_KEYS['getByMobile'], $userData['mobile']));
         return $userId;
     } else {
         return false;
     }
 }
开发者ID:sdgdsffdsfff,项目名称:shfy-giftbag,代码行数:22,代码来源:UserService.php

示例4: insertMappingFlush

    /**
     * 批量插入 giftbag code - campaign - user的mapping的最终操作
     */
    private function insertMappingFlush()
    {
        if (empty($this->mappingValues) == false) {
            $db = DatabaseFactory::open();
            $db->createCommand('
				INSERT INTO g_campaign_mapping_giftbag (campaignId,userId, giftbagCode)
				VALUES (' . implode('),(', $this->mappingValues) . ')
			')->execute();
            $this->mappingValues = array();
        }
    }
开发者ID:sdgdsffdsfff,项目名称:shfy-giftbag,代码行数:14,代码来源:GiftBagCommand.php


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