Swoole\RecordSet::fetch PHP Method

fetch() public method

获取一条数据 参数可以制定返回的字段
public fetch ( $field = '' )
$field
    function fetch($field = '')
    {
        return $this->db_select->getone($field);
    }

Usage Example

Example #1
0
 /**
  * 获取记录
  * @param $field
  * @return array
  */
 function getone($field = '')
 {
     $this->limit('1');
     if ($this->auto_cache or !empty($cache_id)) {
         $cache_key = empty($cache_id) ? self::CACHE_PREFIX . '_one_' . md5($this->sql) : self::CACHE_PREFIX . '_all_' . $cache_id;
         global $php;
         $record = $php->cache->get($cache_key);
         if (empty($data)) {
             if ($this->is_execute == 0) {
                 $this->exeucte();
             }
             $record = $this->result->fetch();
             $php->cache->set($cache_key, $record, $this->cache_life);
         }
     } else {
         if ($this->is_execute == 0) {
             $this->exeucte();
         }
         $record = $this->result->fetch();
     }
     if ($field === '') {
         return $record;
     }
     return $record[$field];
 }