public function getAll($sql, $pageCondition = false) { if (is_array($pageCondition)) { $pageCondition['page'] = ($page = functions::uint($pageCondition['page'])) ? $page : 1; $pageCondition['pagesize'] = ($pagesize = functions::uint($pageCondition['pagesize'])) ? $pagesize : 20; $resource = odb::db()->getAll($sql); $rows = count($resource); $pageInfo = functions::pageInfo($rows, $pageCondition['pagesize'], $pageCondition['page']); } $startRow = ($pageCondition['page'] - 1) * $pageCondition['pagesize']; $sql = is_array($pageCondition) ? $sql . " LIMIT {$startRow}, {$pageCondition['pagesize']}" : $sql; $list = odb::db()->getAll($sql, MYSQL_ASSOC); if (is_array($pageCondition)) { $response = array('list' => $list, 'pageInfo' => $pageInfo); return $response; } return $list; }
/** * 根据更新时间来,批量取更新数据,同步到DB * @param $updatetime 上次更新的时间 * @param int $num 从第一页开始,一次2000条记录 */ public function GetUpdateRecord($updatetime, $num = 2000) { if (!($num = functions::uint($num))) { return array(); } $packet = new SocketPacket(); $packet->WriteBegin(self::CMD_GET_UPDATERECORD); $packet->WriteInt($updatetime); $packet->WriteInt($num); $packet->WriteEnd(); if (!$this->SendData($this->MemDataServer[0], $this->MemDataServer[1], $packet, true)) { return false; } if (($recvLen = @socket_recv($this->aSockets[$this->MemDataServer[0]][$this->MemDataServer[1]], $data, 8192, 0)) === false) { //4096 Logs::factory()->debug(@implode('-', array(socket_strerror(socket_last_error()), __LINE__, $mid)), 'C_getupdate.txt'); return false; } $retPacket = new SocketPacket(); $retPacket->SetRecvPacketBuffer($data, $recvLen); $ret = $retPacket->ParsePacket(); $ret === 0 or Logs::factory()->debug(array('updatetime' => $updatetime, 'num' => $num, 'ret' => $ret), 'C_getupdate_err.txt'); $value = $retPacket->ReadInt(); //返回的结果,这里的结果是 有多少个mid,就去多少次,谢谢 for ($i = 1; $i <= $value; $i++) { //根据mid个数,获取 $mid = $retPacket->ReadInt(); //读取mid $midArr[] = $mid; } return $midArr; //返回mid数组 }
public function limit($startRow, $count) { if (!self::$_rcdata['page']) { $startRow = ($startRow = functions::uint($startRow)) ? $startRow : 1; $count = ($count = functions::uint($count)) ? $count : 1; self::$_rcdata['limit'] = "LIMIT {$startRow}, {$count}"; } return self::getInstance(); }