public function row($sql,$sep=' ') {
$query = $this->query($sql);
+#bye($sql);
$result = $query->fetch(PDO::FETCH_NUM);
if (!is_array($result)) return $result;
return join($sep,$result);
if (isset($this->count)) return $this->count;
$sql_count = $this->name;
- if (preg_match('/^[\w_-]+$/',$sql_count)) {
+
+ # We could use it instead of query, but wont be cached ! $this->create_temporary();
+ if ($this->type == 'sql' and $this->name !== DB_TABLE_QUERY_NAME) {
+ if (!$this->sql) return;
+
+ $sql_count = "SELECT COUNT(*) FROM ($this->sql) _table_count" ;
+# NB 08.08.17 if (preg_match('/SELECT.*SELECT|UNION/i',$this->sql)) {
+# NB 08.08.17 $sql_count = "SELECT COUNT(*) FROM ($this->sql) _table_count" ;
+# NB 08.08.17 } else {
+# NB 08.08.17 $sql_count = "SELECT COUNT(*) FROM ".preg_replace('/^SELECT .*?\s+FROM\s+/','',$this->sql);
+# NB 08.08.17 bye($sql_count);
+# NB 08.08.17 }
+
+ } elseif (preg_match('/^[\w_-]+$/',$sql_count)) {
$sql_count = "SELECT count(*) FROM ".$this->sql_name($sql_count);
} else {
$sth = $this->db()->conn->query($sql,PDO::FETCH_ASSOC);
if (!empty($sth)) $this->status = $sth->fetch();
- }
+ } # if ($this->type == 'sql')
if (empty($this->status)) $this->status = [];
'fields',
'sql',
] as $k) {
- if (!empty($this->status[$k])) continue;
+ if (isset($this->status[$k])) continue;
+# NB 08.08.17 if (!empty($this->status[$k])) continue;
if (empty($key)) {
if (!self::p($k)) continue;