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();
}