1) { $sql = func_get_args(); } elseif (is_string($sql)) { $sql = explode(',', $sql); } else { $sql = (array) $sql; } foreach ($sql as $val) { if (($val = trim($val)) === '') continue; if (strpos($val, '(') === FALSE AND $val !== '*') { if (preg_match('/^DISTINCT\s++(.+)$/i', $val, $matches)) { // Only prepend with table prefix if table name is specified $val = (strpos($matches[1], '.') !== FALSE) ? $this->config['table_prefix'].$matches[1] : $matches[1]; $this->distinct = TRUE; } else { $val = (strpos($val, '.') !== FALSE) ? $this->config['table_prefix'].$val : $val; } $val = $this->driver->escape_column($val); } # RK: table_prefix & escape_column for COUNT($value) AS $alias if (stripos($val, 'count(') !== FALSE AND stripos($val, 'count(*)') === FALSE) { $val = preg_replace('/(count|COUNT)\((.+)\)/','$2', $val); $val = (strpos($val, '.') !== FALSE) ? $this->config['table_prefix'].$val : $val; $val = $this->driver->escape_column($val); if(stripos($val, ' AS ') !== FALSE) { list($column, $alias) = explode(' AS ', $val); $val = "COUNT($column) AS $alias"; } else { $val = "COUNT($val)"; } } $this->select[] = $val; } return $this; } }