Example #1
0
function npi_sql_total($table)
{
    return npi_sql_field("SHOW TABLE STATUS LIKE '" . $table . "'", 'Auto_increment', 0);
}
Example #2
0
    public function cache($a_sql, $sid = '', $private = true)
    {
        global $user;
        $filter_values = array($sid);
        $sql = 'SELECT cache_query
			FROM _search_cache
			WHERE cache_sid = ?';
        if ($private) {
            $sql .= ' AND cache_uid = ?';
            $filter_values[] = $user->d('user_id');
        }
        $query = npi_sql_field(npi_sql_filter($sql, $filter_values), 'cache_query', '');
        if (!empty($sid) && empty($query)) {
            _fatal();
        }
        if (empty($query) && !empty($a_sql)) {
            $sid = md5(unique_id());
            $insert = array('cache_sid' => $sid, 'cache_query' => $a_sql, 'cache_uid' => $user->d('user_id'), 'cache_time' => time());
            $sql = 'INSERT INTO _search_cache' . $this->build('INSERT', $insert);
            $this->query($sql);
            $query = $a_sql;
        }
        $all_rows = 0;
        if (!empty($query)) {
            $result = $this->query($query);
            $all_rows = $this->numrows($result);
            $this->freeresult($result);
        }
        $has_limit = false;
        if (preg_match('#LIMIT (\\d+)(\\, (\\d+))?#is', $query, $limits)) {
            $has_limit = $limits[1];
        }
        return array('sid' => $sid, 'query' => $query, 'limit' => $has_limit, 'total' => $all_rows);
    }