<?php
// +----------------------------------------------------------------------
// | 数据引导文件 [ 天方夜谭快速开发框架 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014~2019 http://www.eirds.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 天方夜谭 <17404785@qq.com>
// +----------------------------------------------------------------------

//检测数据库
if (!file_exists(BASE_PATH.'/Configs/config.php')) {
    header("Location:/Includes/Install/");
    exit();
}

//加载数据库核心文件
require_once('database.php');

//定义数据表前缀
define('PREFIX', $mysql['DB_PREFIX']);

//获取站长联系QQ
define('QQ', $mysql['DB_QQ']);

//加载网站信息
if($rows =$TFYT_DB->get_results('select * from '.PREFIX.'website')){
    $rows = object_array($rows);
    foreach($rows as $row){
        $website[$row['vkey']]=$row['value'];
    }
    TFYT($website);
}

//加载登录的用户信息
$cookiesid = isset($_COOKIE['tfyt_sid'])?$_COOKIE['tfyt_sid']:null;
if($cookiesid && $user=$TFYT_DB->get_row("select * from ".PREFIX."users,".PREFIX."users_service where cookie='{$cookiesid}' and ".PREFIX."users.only=".PREFIX."users_service.only limit 1")){
    $data = $users = object_array($user);
    TFYT('loginuser',$users['uid']);
}

/**
 * 计算数量
 * @param $table
 * @param string $where
 * @param string $key
 * @return mixed|null
 */
function get_count($table, $where = '1=1', $key = '*') {
    $count = $GLOBALS['TFYT_DB']->get_var("select count({$key}) as count from ".PREFIX."{$table} where {$where}");
    return $count;
}

/**
 * 获取指定的数据
 * @param $table
 * @param string $flid
 * @param $where
 * @return array|mixed|null
 */
function get_data($table,$flid,$where){
    $data = $GLOBALS['TFYT_DB']->get_row("select {$flid} from ".PREFIX."{$table} where {$where} limit 1");
    return $data->$flid;
}