本地WordPress文章离线撰写后同步到远端(仅数据库)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了本地WordPress文章离线撰写后同步到远端(仅数据库),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4622字,纯文字阅读大概需要7分钟。
内容图文
//本地数据库 console.log("正在连接本地数据库服务器..."); var localdb,err = mysql.client( server = "localhost"; uid = "root"; pwd = "123456"; ); if(!localdb){ console.log("连接数据库失败",err) return; } localdb.selectDb("blog"); console.log("本地数据库连接成功"); //远端数据库 console.log("正在连接远端数据库服务器..."); var remotedb,err = mysql.client( server = "8.8.8.8"; uid = "xxxxx"; pwd = "xxxxx"; ); if(!remotedb){ console.log("连接数据库失败",err) return; } remotedb.selectDb("blog"); console.log("远端数据库连接成功"); //同步本地日志到远端 console.log("同步本地日志到远端"); //查询最大ID var result = remotedb.query("SELECT max(ID) as MAXID FROM wp_posts"); var remote_post_max_id = result.fetchObject()["MAXID"]; //console.log("远端最大ID:"++remote_post_max_id) result.free(); //查询本地 var result = localdb.query("SELECT ID FROM wp_posts where ID>"++tostring(remote_post_max_id)); var local_post_sync_count = result.numRows(); console.log("需同步"++local_post_sync_count) result.free(); //执行同步 if(local_post_sync_count>0){ //首先替换网址 localdb.exec("update wp_posts set post_content=replace(post_content,‘thinkai.net‘,‘thinkai.net‘) where ID>"++tostring(remote_post_max_id)); var result = localdb.query("SELECT * FROM wp_posts where ID>"++tostring(remote_post_max_id)); for(i=1;local_post_sync_count){ var row = result.fetchObject(); console.log(string.concat("同步ID:",row[‘ID‘]," 标题:",row[‘post_title‘])); remotedb.exec("insert into wp_posts values (@ID, @post_author, @post_date, @post_date_gmt, @post_content, @post_title, @post_excerpt, @post_status, @comment_status, @ping_status, @post_password, @post_name, @to_ping, @pinged, @post_modified, @post_modified_gmt, @post_content_filtered, @post_parent, @guid, @menu_order, @post_type, @post_mime_type, @comment_count)",row) } } //同步本地日志分类到远端 console.log("同步本地日志分类到远端"); //查询最大ID var result = remotedb.query("SELECT max(object_id) as MAXID FROM wp_term_relationships"); var remote_term_max_id = result.fetchObject()["MAXID"]; result.free(); //查询本地 var result = localdb.query("SELECT object_id FROM wp_term_relationships where object_id>"++tostring(remote_term_max_id)); var local_term_sync_count = result.numRows(); console.log("需同步"++local_term_sync_count) result.free(); //执行同步 if(local_term_sync_count>0){ var result = localdb.query("SELECT * FROM wp_term_relationships where object_id>"++tostring(remote_term_max_id)); for(i=1;local_term_sync_count){ var row = result.fetchObject(); console.log(string.concat("同步ID:",row[‘object_id‘])); remotedb.exec("insert into wp_term_relationships values (@object_id, @term_taxonomy_id, @term_order)",row) } } //同步本地分类项目到远端 console.log("同步本地分类项目到远端"); //查询最大ID var result = remotedb.query("SELECT max(term_taxonomy_id) as MAXID FROM wp_term_taxonomy"); var remote_termt_max_id = result.fetchObject()["MAXID"]; result.free(); //查询本地 var result = localdb.query("SELECT term_taxonomy_id FROM wp_term_taxonomy where term_taxonomy_id>"++tostring(remote_termt_max_id)); var local_termt_sync_count = result.numRows(); console.log("需同步"++local_termt_sync_count) result.free(); //执行同步 if(local_termt_sync_count>0){ var result = localdb.query("SELECT * FROM wp_term_taxonomy where term_taxonomy_id>"++tostring(remote_termt_max_id)); for(i=1;local_termt_sync_count){ var row = result.fetchObject(); console.log(string.concat("同步ID:",row[‘term_taxonomy_id‘])); remotedb.exec("insert into wp_term_taxonomy values (@term_taxonomy_id, @term_id, @taxonomy, @description, @parent, @count)",row) } } //查询最大ID var result = remotedb.query("SELECT max(term_id) as MAXID FROM wp_terms"); var remote_term_max_id = result.fetchObject()["MAXID"]; result.free(); //查询本地 var result = localdb.query("SELECT term_id FROM wp_terms where term_id>"++tostring(remote_term_max_id)); var local_term_sync_count = result.numRows(); console.log("需同步"++local_term_sync_count) result.free(); //执行同步 if(local_term_sync_count>0){ var result = localdb.query("SELECT * FROM wp_terms where term_id>"++tostring(remote_term_max_id)); for(i=1;local_term_sync_count){ var row = result.fetchObject(); console.log(string.concat("同步ID:",row[‘term_id‘])); remotedb.exec("insert into wp_terms values (@term_id, @name, @slug, @term_group)",row) } } localdb.close(); remotedb.close(); console.pause();
本地WordPress文章离线撰写后同步到远端(仅数据库)
标签:查询 ace lte replace 替换 rem 数据 gpo bsp
本文系统来源:https://www.cnblogs.com/basstk/p/8340990.html
内容总结
以上是互联网集市为您收集整理的本地WordPress文章离线撰写后同步到远端(仅数据库)全部内容,希望文章能够帮你解决本地WordPress文章离线撰写后同步到远端(仅数据库)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。