在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 — 杨超