PHP code to import member data into ucenter
- 2020-03-31 20:56:27
- OfStack
The member list structure we will use
Core code:
Conclusion:
Import data to ucenter and forum, or other CMS users as small as the operation of the two tables of ucenter, uc_members, uc_memberfields oh, there are not many fields involved in the update, so in general it is easy to import its system data into ucenter for membership and stop.
create table if not exists `net_111cnnet` (
`id` int(11) not null auto_increment,
`username` varchar(32) default null,
`add_time` int(11) default null,
`email` varchar(50) default null,
`password` varchar(50) default null,
`last_login` int(4) default null
primary key (`id`)
) engine=myisam default charset=utf8 auto_increment=1 ;
Core code:
$host ='localhost';
$db ='abc';
$user='root';
$password ='root';
//Database tutorial connection configuration, because my ucenter table is in the same database as the current member table so I just connect once.
try {
$conn = mysql The tutorial _connect($host,$user,$password);
mysql_select_db($db,$conn);
} catch (dbexception $e) {
exit('database connect fail!');//Database error handling
}
$sql ="select * from net_111cnnet "; //Find out all the member data to import into ucenter
$query = mysql_query( $sql,$conn);
while( $rs = mysql_fetch_array( $query ))
{
$uc_sql = "select * from uc_members where username='".$rs['username']."'";
$data = mysql_query( $uc_sql ) ;
if( $data )
{
}
else
{
$salt = substr(uniqid(rand()), -6);
$password = md5($rs['password'].$salt);//Generate the user login password according to the ucenter rules
mysql_query("insert into uc_members set uid= '".$rs['id']."', username='".$rs['username']."', password='$password', email='".$rs['email']."', lastlogintime ='".$rs['last_login']."', regdate='".$rs['add_time']."', salt='$salt'"); //Insert the data into the uc_members table
mysql_query("insert into uc_memberfields set uid='".$rs['id']."'");//Update the uc_memberfields table.
}
}
exit(' All users have been imported into ucenter');
Conclusion:
Import data to ucenter and forum, or other CMS users as small as the operation of the two tables of ucenter, uc_members, uc_memberfields oh, there are not many fields involved in the update, so in general it is easy to import its system data into ucenter for membership and stop.