return $sth->fetchAll($style);
}
- /*
- */
function query2a($sql) {
$r = $this->conn->query($sql,PDO::FETCH_COLUMN);
return $r ? $r->fetch() : $r;
return ','.join(',',$select);
}
- /******************************************************************
- Html Output
- ******************************************************************/
+ public function rows_count() {
+ $opt = [ 'count' => 1 ];
+ return $this->db()->row($this->rows_sql($opt));
+ }
+
public function rows_sql(&$opt=[]) {
if (isset($this->orderby)) self::pdef('orderby',$this->orderby);
if (self::p('order')) self::pset('orderby',self::p('orderby').' '.self::p('order')); # from Wordpress
+ $count = empty($opt['count']) ? 0 : 1;
//
// Select
if (stripos($this->name,' ') !== false) {
$sql = $this->name;
$limit = $where = '';
+ if ($count) $sql = "SELECT count(*) FROM ".$this->sql_name();
} else {
}
- $sql = "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras();
+ $sql = $count ? "SELECT count(*)" : "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras();
$sql .= " FROM ".$this->sql_name();
$sql .= $where;
#bye($sql);
- if ($this->p('orderby')) $sql .= ' ORDER BY '.$this->p('orderby');
+ if ($this->p('orderby') and !$count) $sql .= ' ORDER BY '.$this->p('orderby');
if ($limit = $this->db()->limit) {
$sql .= ' LIMIT '.$limit;
}
+ if ($count) return $sql;
+
//
// Get results
//
public function headers() {
if (self::php_cli()) return false;
- #header('Content-type: ' . self::$content_type);
header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : ""));
if (isset($this->expires)) self::headers_cache($this->expires);
if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="'
. $this->title2filename($this->title,self::$content_type)
.'"');
- #self::headers_cache();
return true;
}
public function head() {
$head = '';
- #$head .= '</head>'.NB_EOL; return $head;
-
if ($this->title) $head .= $this->tag('title',$this->title) . NB_EOL;
if (preg_match('/tml$/',self::$content_type)) {
}
}
- #debug($urls);
+
return $urls;
}
}
public static function nav_parse($array) {
- #$v = &$sep;
$title = [];
$nav = [];
$hash = [];
'/default'.(PRODUCTION ? '.min' : '').'.js',
];
public $ext;
+ public $expires;
# Others
public $expode_args = '&';
'title',
'css',
'js',
- 'format_html_ua_exp'
+ 'format_html_ua_exp',
+ 'expires',
] as $k) {
$env = 'DBQ_'.strtoupper($k);
'sep' => $this->sep_title,
#'body_class' => 'fixed',
]);
+ if (isset($this->expires)) $this->page->expires = $this->expires;
if ($run) $this->run();
}
} elseif ($action == 'sql') {
$this->page(['sql'=>$this->table->sql()]);
+ } elseif ($action == 'count') {
+ $this->page(['count'=>$this->table->rows_count()]);
+
} elseif ($action == 'fields') {
$this->page($this->table,'fields_rows');
if ($DBQ_ENVS = "") { set $DBQ_ENVS ""; }
fastcgi_param DBQ_ENVS $DBQ_ENVS;
+
+ if ($DBQ_EXPIRES = "") { set $DBQ_EXPIRES ""; }
+ fastcgi_param DBQ_EXPIRES $DBQ_EXPIRES;
}