think-orm
think-orm copied to clipboard
在php7.3及以上版本中,会出错
代码位置 :\topthink\think-orm\src\db\BaseQuery.php 原代码:
public function field($field)
{
if (empty($field)) {
return $this;
} elseif ($field instanceof Raw) {
$this->options['field'][] = $field;
return $this;
}
if (is_string($field)) {
if (preg_match('/[\<\'\"\(]/', $field)) {
return $this->fieldRaw($field);
}
$field = array_map('trim', explode(',', $field));
}
if (true === $field) {
// 获取全部字段
$fields = $this->getTableFields();
$field = $fields ?: ['*'];
}
if (isset($this->options['field'])) {
$field = array_merge((array) $this->options['field'], $field);
}
$this->options['field'] = array_unique($field);
return $this;
}
修改为
public function field($field)
{
if (empty($field)) {
return $this;
} elseif ($field instanceof Raw) {
$this->options['field'][] = $field;
return $this;
}
if (is_string($field)) {
if (preg_match('/[\<\'\"\(]/', $field)) {
return $this->fieldRaw($field);
}
$field = array_map('trim', explode(',', $field));
}
if (true === $field) {
// 获取全部字段
$fields = $this->getTableFields();
$field = $fields ?: ['*'];
}
if (isset($this->options['field'])) {
$field = array_merge((array) $this->options['field'], $field);
}
$this->options['field'] = @array_unique($field);
return $this;
}
$this->options['field'] = array_unique($field); 这一行增加一个@,忽略报错,否则有时联表分组查询后,先查count,再查select会报错。如下图: