Swoole\Model::put PHP Méthode

put() public méthode

插入一条新的记录到表
public put ( $data ) : integer
$data Array 必须是键值(表的字段对应值)对应
Résultat integer
    public function put($data)
    {
        if (empty($data) or !is_array($data)) {
            return false;
        }
        if ($this->db->insert($data, $this->table)) {
            $lastInsertId = $this->db->lastInsertId();
            if ($lastInsertId == 0) {
                return true;
            } else {
                return $lastInsertId;
            }
        } else {
            return false;
        }
    }

Usage Example

Exemple #1
0
 function set($key, $value, $expire = 0)
 {
     $in['ckey'] = $key;
     if (is_array($value)) {
         $value = serialize($value);
     }
     $in['cvalue'] = $value;
     if ($expire == 0) {
         $in['expire'] = $expire;
     } else {
         $in['expire'] = time() + $expire;
     }
     $in['sid'] = $this->shard_id;
     $this->model->put($in);
 }