Cml\Db\MySql\Pdo::update PHP Метод

update() публичный Метод

根据key更新一条数据
public update ( string $key, array | null $data = null, boolean $and = true, mixed $tablePrefix = null ) : boolean
$key string eg 'user-uid-$uid' 如果条件是通用whereXX()、表名是通过table()设定。这边可以直接传$data的数组
$data array | null
$and boolean 多个条件之间是否为and true为and false为or
$tablePrefix mixed 表前缀 不传则获取配置中配置的前缀
Результат boolean
    public function update($key, $data = null, $and = true, $tablePrefix = null)
    {
        is_null($tablePrefix) && ($tablePrefix = $this->tablePrefix);
        $tableName = $condition = '';
        if (is_array($data)) {
            list($tableName, $condition) = $this->parseKey($key, $and, true, true);
        } else {
            $data = $key;
        }
        $tableName = empty($tableName) ? $this->getRealTableName(key($this->table)) : $tablePrefix . $tableName;
        if (empty($tableName)) {
            throw new \InvalidArgumentException(Lang::get('_PARSE_SQL_ERROR_NO_TABLE_', 'update'));
        }
        $s = $this->arrToCondition($data, substr($tableName, strlen($tablePrefix)));
        $whereCondition = $this->sql['where'];
        $whereCondition .= empty($condition) ? '' : (empty($whereCondition) ? 'WHERE ' : '') . $condition;
        if (empty($whereCondition)) {
            throw new \InvalidArgumentException(Lang::get('_PARSE_SQL_ERROR_NO_CONDITION_', 'update'));
        }
        $stmt = $this->prepare("UPDATE {$tableName} SET {$s} {$whereCondition}", $this->wlink);
        $this->execute($stmt);
        $this->setCacheVer($tableName);
        return $stmt->rowCount();
    }