Swoole\Model::put PHP Method

put() public method

插入一条新的记录到表
public put ( $data ) : integer
$data Array 必须是键值(表的字段对应值)对应
return 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

コード例 #1
0
ファイル: DBCache.php プロジェクト: kilmas/framework
 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);
 }