Cml\Db\MySql\Pdo::delete PHP Method

delete() public method

根据key值删除数据
public delete ( string $key = '', boolean $and = true, mixed $tablePrefix = null ) : boolean
$key string eg: 'user-uid-$uid'
$and boolean 多个条件之间是否为and true为and false为or
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
return boolean
    public function delete($key = '', $and = true, $tablePrefix = null)
    {
        is_null($tablePrefix) && ($tablePrefix = $this->tablePrefix);
        $tableName = $condition = '';
        empty($key) || (list($tableName, $condition) = $this->parseKey($key, $and, true, true));
        $tableName = empty($tableName) ? $this->getRealTableName(key($this->table)) : $tablePrefix . $tableName;
        if (empty($tableName)) {
            throw new \InvalidArgumentException(Lang::get('_PARSE_SQL_ERROR_NO_TABLE_', 'delete'));
        }
        $whereCondition = $this->sql['where'];
        $whereCondition .= empty($condition) ? '' : (empty($whereCondition) ? 'WHERE ' : '') . $condition;
        if (empty($whereCondition)) {
            throw new \InvalidArgumentException(Lang::get('_PARSE_SQL_ERROR_NO_CONDITION_', 'delete'));
        }
        $stmt = $this->prepare("DELETE FROM {$tableName} {$whereCondition}", $this->wlink);
        $this->execute($stmt);
        $this->setCacheVer($tableName);
        return $stmt->rowCount();
    }