Ejemplo n.º 1
0
function mysql_connect_test($config, $type)
{
    global $setting;
    static $error_code = array('connect_error' => -1, 'table_error' => -2);
    static $db;
    $ret = true;
    if ($db === null) {
        require_once DISCUZ_ROOT . './include/db.class.php';
        $db = new db_mysql();
    }
    $db->set_config($config);
    $check = $db->connect(false);
    if (!$check) {
        $ret = $error_code['connect_error'];
    } else {
        if (isset($setting['tablecheck'][$type])) {
            $find = $db->fetch_first("SHOW TABLES LIKE '{$config[tablepre]}{$setting['tablecheck'][$type]}'");
            if (!$find) {
                $ret = $error_code['table_error'];
            }
        }
    }
    $db->close();
    return $ret;
}
Ejemplo n.º 2
0
/**
 * 得到帖子信息
 * @param $tid - 帖子ID
 * @param $returnpid - 返回首帖pid
 * @param $msgleng - 內容截斷的長度
 */
function list_threads($tid = 0, $msgleng = 255)
{
    global $_G, $_SC;
    $tid = intval($tid);
    $msgleng = intval($msgleng);
    $ret_thread = array();
    if ($tid > 0) {
        $bbs_dbpre = $_SC['bbs_dbpre'];
        $db = new db_mysql(array(1 => array('tablepre' => $_SC['bbs_dbpre'], 'dbcharset' => $_SC['bbs_dbcharset'], 'dbhost' => $_SC['bbs_dbhost'], 'dbuser' => $_SC['bbs_dbuser'], 'dbpw' => $_SC['bbs_dbpw'], 'dbname' => $_SC['bbs_dbname'])));
        $db->connect();
        //$db->charset = $_SC['bbs_dbcharset'];
        //$db->connect($_SC['bbs_dbhost'], $_SC['bbs_dbuser'], $_SC['bbs_dbpw'], $_SC['bbs_dbname'], 0, 1);
        $query = $db->query("SELECT pid, authorid, author, subject, message FROM {$bbs_dbpre}posts WHERE tid='{$tid}' AND first='1' LIMIT 1");
        $ret_thread = $db->fetch_array($query);
        if (!empty($ret_thread['message'])) {
            $ret_thread['message'] = messagecutstr($ret_thread['message'], $msgleng);
        }
        $db->close();
        unset($db);
    }
    return $ret_thread;
}
Ejemplo n.º 3
0
function syncpost($itemid, $mname)
{
    if (!in_array($mname, array('album', 'good', 'notice', 'consume', 'groupbuy'))) {
        if ($mname == 'album') {
            syncalbum($itmeid);
            return false;
        }
    }
    global $_G, $_SC, $_SGLOBAL;
    $bbs_dbpre = $_SC['bbs_dbpre'];
    $db = new db_mysql(array(1 => array('tablepre' => $_SC['bbs_dbpre'], 'dbcharset' => $_SC['bbs_dbcharset'], 'dbhost' => $_SC['bbs_dbhost'], 'dbuser' => $_SC['bbs_dbuser'], 'dbpw' => $_SC['bbs_dbpw'], 'dbname' => $_SC['bbs_dbname'], 'silent' => true)));
    $db->connect();
    $item = DB::fetch_first("SELECT i.*, m.* FROM " . DB::table($mname . "items") . " i LEFT JOIN " . DB::table($mname . "message") . " m ON i.itemid = m.itemid WHERE i.itemid = '{$itemid}' AND i.grade = 3");
    if (empty($item)) {
        $db->close();
        unset($db);
        return false;
    }
    getpanelinfo($item['shopid']);
    $fid = $_SGLOBAL['panelinfo']['syncfid'];
    if (!checkbbsfid($fid)) {
        $db->close();
        unset($db);
        return false;
    }
    //插入主題信息
    $author = $_SGLOBAL['panelinfo']['username'];
    $authorid = $_SGLOBAL['panelinfo']['uid'];
    $subject = "[" . b_lang($mname) . "]" . $item['subject'];
    $message = postformat($mname, $item);
    $posttable_info = $db->result_first("SELECT svalue FROM {$bbs_dbpre}common_setting WHERE skey = 'posttable_info'");
    $posttableid = 0;
    if (!empty($posttable_info)) {
        $posttable_info = unserialize($posttable_info);
        if (is_array($posttable_info)) {
            foreach ($posttable_info as $key => $info) {
                if ($info['type'] == 'primary') {
                    $posttableid = $key;
                }
            }
        }
    }
    if (!$posttableid) {
        $tablename = 'forum_post';
    } else {
        $tablename = "forum_post_{$posttableid}";
    }
    if (empty($item['bbstid'])) {
        $db->query("INSERT INTO {$bbs_dbpre}forum_thread (fid, posttableid, author, authorid, subject, dateline, lastpost, lastposter)\n        VALUES ('{$fid}', '{$posttableid}', '{$author}', '{$authorid}', '{$subject}', '{$_G['timestamp']}', '{$_G['timestamp']}', '{$author}')");
        $tid = $db->insert_id();
        $db->query("UPDATE {$bbs_dbpre}common_member_field_home SET recentnote = '{$subject}' WHERE uid = '{$authorid}'");
        $db->query("INSERT INTO {$bbs_dbpre}forum_post_tableid (pid) values (null)");
        $pid = $db->insert_id();
        if ($pid % 1024 == 0) {
            $db->query("DELETE FROM {$bbs_dbpre}forum_post_tableid WHERE pid<{$pid}");
        }
        $db->query("REPLACE INTO {$bbs_dbpre}common_syscache (cname, ctype, dateline, data) VALUES ('max_post_id', '0', '{$_G['timestamp']}', '{$pid}')");
        if (!$posttableid) {
            $tablename = 'forum_post';
        } else {
            $tablename = "forum_post_{$posttableid}";
        }
        $db->query("INSERT INTO {$bbs_dbpre}{$tablename} SET `fid`='{$fid}',`tid`='{$tid}',`first`='1',`author`='{$author}',`authorid`='{$authorid}',`subject`='{$subject}',`dateline`='{$_G['timestamp']}',`message`='{$message} ',`useip`='unknown',`invisible`='0',`anonymous`='0',`usesig`='1',`htmlon`='0',`bbcodeoff`='0',`smileyoff`='-1',`parseurloff`='',`attachment`='0',`tags`='',`pid`='{$pid}'");
        $db->query("UPDATE {$bbs_dbpre}forum_forum SET lastpost='{$tid} {$subject} {$_G[timestamp]} {$author}', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='{$fid}'");
        $db->query("UPDATE {$bbs_dbpre}common_stat SET `thread`=`thread`+1 WHERE daytime='" . date("Ymd", $_G[timestamp]) . "'");
        updatetable($mname . 'items', array('bbstid' => $tid), array('itemid' => $item['itemid']));
    } else {
        $tid = $item['bbstid'];
        $db->query("UPDATE {$bbs_dbpre}forum_thread SET subject='" . $subject . "' WHERE tid='{$tid}'");
        $pid = $db->result_first("SELECT pid FROM {$bbs_dbpre}{$tablename} WHERE tid = '{$tid}' AND first = 1");
        $db->query("UPDATE {$bbs_dbpre}{$tablename} SET message='{$message}' WHERE pid='{$pid}' AND tid = '{$tid}' AND first = 1");
    }
}