本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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();
}
}