雅虎新闻|| BBC新闻|| CNN新闻|| 美元指数|| 中国期货指数|| 股票指数|| 黄金|| 外汇|| 英汉互译|| 昭放工具
163邮箱|| 126邮箱|| 新浪邮箱|| 企业邮箱|| 21cn邮箱|| tom邮箱|| 搜狐邮箱|| hotmail邮箱|| msn邮箱|| qq邮箱

用户登录

设为主页| 淘宝铺| 加入收藏|
您的IP:3.133.139.28您的操作系统:Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
个人便签
知识库
批量同步dz x和ucenter1.6的用户

在ucenter中已经有了,但是没有在dzx中。用下面的代码。

 

<?php

$dbserver ='localhost'; //此处改成数据库服务器地址

$dbuser ='';//此处写数据库用户名

$dbpwd ='';//数据库密码

$dbname ='';//数据库名称

$charset ='utf8';//此处写字符集gbk或者utf8

$uc_pre ='pre_ucenter_';//uc表前缀

$dx_pre ='pre_';//Discuz! X2表前缀

//此行开始向下不要改动

$connect=mysql_connect($dbserver,$dbuser,$dbpwd) or die("无法连接数据库");

@mysql_select_db($dbname,$connect);

mysql_query("set names $charset");

$query = mysql_query("SELECT * FROM `{$uc_pre}members`  WHERE  `uid` not in(select `uid` from `{$dx_pre}common_member`) ",$connect);

while($user = mysql_fetch_array($query)) {

  $password=$user[password];

 

  $sql = " REPLACE INTO `".$dx_pre."common_member` (uid,username,password,adminid,groupid,regdate,email) VALUES (".$user[uid].", '".$user[username]."', '".$password."',0,10,".$user[regdate].",'".$user[email]."') ";

  mysql_query($sql);

  $sql = "REPLACE INTO `{$dx_pre}common_member_field_forum` (uid) VALUES (".$user[uid].")";

  mysql_query($sql );

  $sql = " REPLACE INTO `{$dx_pre}common_member_field_home` (uid) VALUES (".$user[uid].")";

  mysql_query($sql);

}

echo "finished";

?>

 

如果涉及到其他应用,在添加会员以后,只是与uc同步,未与dzx同步,则需要在应用的uc_client的user.php中,add_user函数,return $uid前,添加如下代码:

  $time = time();

  $this->db->query("INSERT INTO dbname.pre_common_member(uid,email,username,password,adminid,groupid,regdate,credits,timeoffset) VALUES ($uid,'$email','$username','$password',0,10,'$time',0,'9999')");

  $this->db->query("INSERT INTO dbname.pre_common_member_status(uid,regip,lastip,lastvisit,lastactivity,lastpost,lastsendmail) VALUES ($uid,'$regip','$regip','$time','$time',0,0)");

  $this->db->query("INSERT INTO dbname.pre_common_member_profile(uid) VALUES ($uid)");

  $this->db->query("INSERT INTO dbname.pre_common_member_field_forum(uid) VALUES ($uid)");

  $this->db->query("INSERT INTO dbname.pre_common_member_field_home(uid) VALUES ($uid)");

  $this->db->query("INSERT INTO dbname.pre_common_member_count(uid,extcredits2) VALUES ($uid,2)");

星期二, 07/17/2012 - 13:42 — 杨超