public function __construct() { $_dbConf = CApp::app()->getConf('Db'); foreach ($_dbConf as $identify => $conf) { $this->_Db[$identify] = CDb::createDb($conf['host'], $conf['user'], $conf['pwd'], $conf['dbName']); } }
static function setup($string, $username, $password, $pdo_options = array()) { try { self::$link = new PDO($string, $username, $password, $pdo_options); self::$link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); } catch (PDOException $e) { die("Error!: " . $e->getMessage() . "<br/>"); } }
public function __construct() { parent::__construct(); $this->init(); }
break; case 'LOCALNAME': $buddyLocalName = isset($valsArr[$i]['value']) ? base64_decode($valsArr[$i]['value']) : -1; break; case 'IMPRESA': $buddyImpresa = isset($valsArr[$i]['value']) ? base64_decode($valsArr[$i]['value']) : -1; break; case 'PROVINCE': $buddyProvince = isset($valsArr[$i]['value']) ? $valsArr[$i]['value'] : -1; break; case 'CITY': $buddyCity = isset($valsArr[$i]['value']) ? $valsArr[$i]['value'] : -1; break; } } $db = new CDb($srvMobile); /* init database */ $sql = "select * from fx_config where fx_config.key='mobile'"; $retArr = $db->fetchQueryAll($sql); if (count($retArr) == 1) { $v = $retArr[0]['value']; if ($v != $srvMobile) { $db->execute('truncate table fx_participate'); $db->execute('truncate table fx_guestbook'); $db->execute('truncate table fx_buddies'); $db->execute('truncate table fx_game_kaixincidian_scores'); $db->execute('truncate table fx_game_kaixincidian_records'); $db->execute('truncate table fx_incomming_messages'); $db->execute('truncate table fx_log_articles'); $db->execute('truncate table fx_vote_records'); $db->execute('update fx_vote_options set ballots=0');
public static function timer($svcMobile, $tick) { // 活动参与定时抽奖模块 //每天晚上12点自动抽奖 $autoRaffleTime = "00"; $time = date('H'); if ($time != $autoRaffleTime) { die; } //判断自动抽奖开关,是否打开 $db = new CDb($svcMobile); $sql = "select * from fx_config where fx_config.key='AUTO_RAFFLE_ON'"; $rows = $db->fetchQueryAll($sql); if (count($rows) == 0) { die; } if ($rows[0]['value'] == 0) { die; } // 自动抽奖关闭 //判断当天是否已经抽奖 $time = date('Y-m-d H'); $sql = "select * from fx_config where fx_config.key='AUTO_RAFFLE_REC'"; //抽奖记录 $rows = $db->fetchQueryAll($sql); if ($time == $rows[0]['value']) { die; } //当天已经抽奖 //获取抽奖事件ID $sql = "select * from fx_config where fx_config.key='AUTO_RAFFLE_EVENT_ID'"; //抽奖记录 $rows = $db->fetchQueryAll($sql); $eventID = $rows[0]['value']; //获取抽奖数目 $sql = "select * from fx_config where fx_config.key='AUTO_RAFFLE_NUMBER'"; //抽奖数目 $rows = $db->fetchQueryAll($sql); $number = $rows[0]['value']; //当天未抽奖,抽奖并记录状态。从昨天记录中抽取 $lastDay = date("Y-m-d", time() - 24 * 60 * 60); $sql = "SELECT b.sid,b.mobile,b.nick_name,b.local_name,a.id,a.buddy_id,a.event_id,a.add_time,left(from_unixtime(a.add_time),10) as timestr "; $sql .= " FROM fx_participate a Inner Join fx_buddies b ON a.buddy_id = b.id where event_id={$eventID} and left(from_unixtime(a.add_time),10)='{$lastDay}' order by a.id desc"; //echo $sql."\n"; $rows = $db->fetchQueryAll($sql); //print_r($rows); $count = count($rows); //随机,$number:个数 if ($count < $number) { //'数量太少,全部中奖'); $randArr = array(); for ($i = 0; $i < $count; $i++) { $randArr[] = $i + 1; } } else { $number = intval($number); $randArr = array(); for ($i = 0; $i < $number; $i++) { while ($r = rand(1, $count)) { if (!in_array($r, $randArr)) { $randArr[] = $r; break; } } } } $retArr = array(); for ($i = 0; $i < count($randArr); $i++) { $retArr[] = $rows[$randArr[$i] - 1]; $sql = "insert into fx_auto_raffle(event_id,buddy_id,raffle_time) values({$eventID},{$rows[$randArr[$i] - 1]['buddy_id']},'{$lastDay}')"; echo $sql . "\n"; $db->execute($sql); } // 记录已经抽取 $sql = "update fx_config set value='{$time}' where fx_config.key='AUTO_RAFFLE_REC'"; $db->execute($sql); }