discuz 3x 通过 SQL 插入帖子内容(采集开发)

其中需要变更的表有(pre 为表前缀,根据实际替换):

  • pre_forum_thread
  • pre_forum_post_tableid
  • pre_forum_post
  • pre_forum_forum
  • pre_forum_newthread
        START TRANSACTION;

        SET @views = 1;
        SET @_status = 32;
        SET @maxposition = 1;
        SET @premsg = '';
        SET @useip = '127.0.0.1';
        SET @_port = 36790;
        SET @usesig = 1;
        SET @position = 1;
        SET @_first = 1;
        SET @now_timestamp = UNIX_TIMESTAMP();

		# 版块 ID
        SET @fid = 3;
        # 作者 ID
        SET @author_id = 1;
        # 作者名称
        SET @author_name = 'admin';
        # 帖子标题
        SET @title = '我是帖子标题';
        # 帖子内容
        SET @message = '我是帖子内容';

        INSERT INTO `pre_forum_thread`
        (fid, author, authorid, `subject`, dateline, lastpost, lastposter, views, status, maxposition)
        VALUES
        (@fid, @author_name, @author_id, @title, @now_timestamp, @now_timestamp, @author_name, @views, @_status, @maxposition);

        SET @new_thread_id = LAST_INSERT_ID();

        INSERT INTO `pre_forum_post_tableid` (`pid`) VALUES (null);

        SET @new_pid = LAST_INSERT_ID();

        INSERT INTO `pre_forum_post`
        (pid, fid, tid, `first`, author, authorid, `subject`, dateline, premsg, message, useip, `port`, usesig, position, htmlon, bbcodeoff, smileyoff)
        VALUES
        (@new_pid, @fid, @new_thread_id, @_first, @author_name, @author_id, @title, @now_timestamp, @premsg, @message, @useip, @_port, @usesig, @position, 1, -1, -1);

        UPDATE `pre_forum_forum` 
        SET threads=threads+1, posts=posts+1, lastpost=CONCAT(@new_thread_id, "\t", @title, "\t", UNIX_TIMESTAMP(), "\t", @author_name)
        WHERE fid=@fid;

        INSERT INTO `pre_forum_newthread` (`tid`, `fid`, `dateline`) VALUES (@new_thread_id, @fid, UNIX_TIMESTAMP());

        COMMIT;

参考

  • https://www.cnblogs.com/it-tsz/p/14270202.html
  • https://blog.csdn.net/weixin_36225424/article/details/113342677
  • https://blog.csdn.net/weixin_30946627/article/details/115954858

猜你喜欢

转载自blog.csdn.net/xchenhao/article/details/130040151