function banip_read_by_ip($ip)
{
    $ip = long2ip(ip2long($ip));
    // 安全过滤
    $arr = explode('.', $ip);
    $banip = db_find_one("SELECT * FROM `bbs_banip` WHERE ip0='{$arr['0']}' AND ip1='{$arr['1']}' AND ip2='{$arr['2']}' AND ip3='{$arr['3']}' LIMIT 1");
    banip_format($banip);
    return $banip;
}
function table_day_cron($crontime = 0)
{
    global $time;
    $crontime = $crontime ? $crontime : $time;
    list($y, $m, $d) = explode('-', date('Y-n-j', $crontime));
    // 往前推8个小时,确保在前一天。
    $table_map = array('bbs_thread' => 'tid', 'bbs_post' => 'pid', 'bbs_user' => 'uid');
    foreach ($table_map as $table => $col) {
        $arr = db_find_one("SELECT MAX(`{$col}`) maxid FROM `{$table}` WHERE create_date<{$crontime}");
        $maxid = $arr['maxid'];
        $arr = db_find_one("SELECT COUNT(*) `count` FROM `{$table}` WHERE create_date<{$crontime}");
        $count = $arr['count'];
        db_exec("REPLACE INTO bbs_table_day SET `year`='{$y}', `month`='{$m}', `day`='{$d}', `create_date`='{$crontime}', `table`='{$table}', `maxid`='{$maxid}', `count`='{$count}'");
    }
}
Exemple #3
0
function online__read($sid)
{
    return db_find_one("SELECT * FROM `bbs_online` WHERE sid='{$sid}'");
}
Exemple #4
0
function user_read($uid)
{
    return db_find_one("SELECT * FROM `test_user` WHERE uid='{$uid}'");
}
Exemple #5
0
function friendlink_read($linkid)
{
    return db_find_one("SELECT * FROM `bbs_friendlink` WHERE linkid='{$linkid}'");
}
Exemple #6
0
function thread_url_read_by_url($url)
{
    $arr = db_find_one("SELECT * FROM bbs_thread_url WHERE url='{$url}'");
    return $arr ? $arr['tid'] : 0;
}
function modlog__read($logid)
{
    return db_find_one("SELECT * FROM `bbs_modlog` WHERE logid='{$logid}'");
}
Exemple #8
0
function forum_access_count($cond = array())
{
    $cond = cond_to_sqladd($cond);
    $arr = db_find_one("SELECT COUNT(*) AS num FROM `bbs_forum_access` {$cond}");
    return $arr['num'];
}
function ipaccess_read($ip)
{
    return db_find_one("SELECT * FROM `bbs_ipaccess` WHERE ip='{$ip}'");
}
function group__read($gid)
{
    return db_find_one("SELECT * FROM `bbs_group` WHERE gid='{$gid}'");
}
function qq_login_read_user_by_openid($openid)
{
    $arr = db_find_one("SELECT * FROM bbs_user_open_plat WHERE openid='{$openid}'");
    if ($arr) {
        $arr2 = user_read($arr['uid']);
        if ($arr2) {
            $arr = array_merge($arr, $arr2);
        } else {
            db_exec("DELETE FROM bbs_user_open_plat WHERE openid='{$openid}'");
            return FALSE;
        }
    }
    return $arr;
}
Exemple #12
0
/*
	功能:操作数据库
	注意:发生错误的时候,返回 FALSE
*/
chdir('../../../');
// 请修改配置文件,设置正确的 mysql 账号密码
$conf = (include './simple/4/conf.php');
include './xiunophp/xiunophp.php';
// 创建表
$r = db_exec("DROP TABLE IF EXISTS `test_user`");
$r = db_exec("CREATE TABLE `test_user` (\n  uid int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户编号',\n  username char(32) NOT NULL DEFAULT '' COMMENT '用户名',\n  password char(32) NOT NULL DEFAULT '' COMMENT '密码',\n  PRIMARY KEY (uid)\n) ENGINE=MyISAM  DEFAULT CHARSET=utf8");
// 插入数据
$r = db_exec("INSERT INTO `test_user` SET username='******'");
$r = db_exec("INSERT INTO `test_user` SET username='******'");
// 查找一条数据
$arr = db_find_one("SELECT * FROM `test_user` WHERE username='******'");
print_r($arr);
// 查找多条数据
$arrlist = db_find("SELECT * FROM `test_user` WHERE uid>0");
print_r($arrlist);
/*
结果输出:
Array
(
    [uid] => 1
    [username] => Jack
)
Array
(
    [0] => Array
        (
function article__read($articleid)
{
    return db_find_one("SELECT * FROM `bbs_article` WHERE articleid='{$articleid}'");
}
function mythread_read($uid, $tid)
{
    return db_find_one("SELECT * FROM `bbs_mythread` WHERE uid='{$uid}' AND tid='{$tid}' LIMIT 1");
}
Exemple #15
0
<?php

define('APP_NAME', 'test');
chdir(getcwd() . '/../');
include './XiunoPHP.3.0.php';
$user = db_find_one("SELECT * FROM `user` WHERE uid='1'");
x('select', $user['uid'], '1');
$r = db_exec("INSERT INTO user SET uid=1000, username='******'");
x('insert', $r, 1000);
$arr = db_find_one("SELECT * FROM user WHERE uid='1000'");
x('select', $arr['uid'], '1000');
$r = db_exec("DELETE FROM user WHERE uid='1000'");
x('insert', $r, 1);
$r = db_find_one("SELECT * FROM user WHERE uid='0'");
x('select', $r, NULL);
function x($info, $a, $b)
{
    echo "{$info}: ... " . ($a === $b ? 'true' : 'false' . ", " . var_export($a, 1) . ", " . var_export($b, 1)) . "\r\n";
}
function thread_check_lastpid($tid, $lastpid)
{
    // 查找最新的 pid
    $thread = thread_read_cache($tid);
    if (empty($thread)) {
        return;
    }
    if ($thread['lastpid'] == $lastpid) {
        $arr = db_find_one("SELECT pid FROM bbs_post WHERE tid='{$tid}' ORDER BY pid DESC LIMIT 1");
        if (empty($arr)) {
            return;
        }
        $lastpid = $arr['pid'];
        db_exec("UPDATE bbs_thread SET lastpid='{$lastpid}' WHERE tid='{$tid}'");
        // 如果在最新主题当中,应该清理掉。
        //thread_lastpid_truncate();
    }
}
function thread_new_count()
{
    $arr = db_find_one("SELECT COUNT(*) AS num FROM `bbs_thread_new`");
    return $arr['num'];
}
Exemple #18
0
function post__read($pid)
{
    return db_find_one("SELECT * FROM `bbs_post` WHERE pid='{$pid}'");
}
Exemple #19
0
function attach_count($cond = array())
{
    $cond = cond_to_sqladd($cond);
    $arr = db_find_one("SELECT COUNT(*) AS num FROM `bbs_attach` {$cond}");
    return $arr['num'];
}
Exemple #20
0
function kv_get($k)
{
    $k = addslashes($k);
    $arr = db_find_one("SELECT k,v FROM bbs_kv WHERE k='{$k}'");
    return $arr ? xn_json_decode($arr['v']) : NULL;
}
function forum__read($fid)
{
    $forum = db_find_one("SELECT * FROM `bbs_forum` WHERE fid='{$fid}'");
    return $forum;
}
Exemple #22
0
function user_read_by_username($username)
{
    $user = db_find_one("SELECT * FROM `bbs_user` WHERE username='******' LIMIT 1");
    user_format($user);
    return $user;
}
function myagree_count_by_pid($pid)
{
    $arr = db_find_one("SELECT COUNT(*) AS num FROM `bbs_myagree` WHERE pid='{$pid}'");
    return intval($arr['num']);
}
function guest_agree_count_by_ip($ip)
{
    $ip = intval($ip);
    $arr = db_find_one("SELECT COUNT(*) AS num FROM `bbs_guest_agree` WHERE ip='{$ip}'");
    return $arr['num'];
}