php 把会员数据导入到ucenter代码

 更新时间:2016年11月25日 16:28  点击:1385
导入数据到ucenter与论坛,或其它 cms用户同小只要操作ucenter的两张表就行了,uc_members,uc_memberfields哦,涉及到更新的字段也不多,所以总体来讲把它系统的数据导入到ucenter进行会员同止步是很简单的。

/*
我们要用的会员表结构

 代码如下 复制代码
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 ;


会员表
*/

 代码如下 复制代码
$host ='localhost';
$db ='abc';
$user='root';
$password ='root';

//数据库教程连接配置,由于我的ucenter表与现在的会员表在同一个数据库所以就一次连接就行了。

 代码如下 复制代码

try { 
 $conn = mysql教程_connect($host,$user,$password);
 mysql_select_db($db,$conn);
} catch (dbexception $e) { 
 exit('database connect fail!');// 数据库出错处理处
}

$sql ="select * from net_111cnnet "; //查出要导入到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);//按照ucenter规则生成用户登陆密码
  
  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'"); //把数据插入到uc_members表
  mysql_query("insert into uc_memberfields set uid='".$rs['id']."'");//更新uc_memberfields表。
 }
}
exit('所有用户己导入到ucenter');

/*
总结:
 
 本文章原创于www.111cn.net转载的朋友请尊重他人的劳动成果,注明来源。
*/

树型结构是很多程序会员会用到的,上面这款关于树型结构操作类,很好的解决了这个问题哦。

/***************************************************************
* 树型结构操作类(如果可以写成存储过程最理想)
*
*  ***************************************************************/

class treenode {
        var $f_id = 'id';
        var $f_pid = 'pid';
        var $f_lft = 'lft';
        var $f_rgt = 'rgt';
        var $f_s = 'sequence';
        var $f_level = 'lev';
        var $f_child_num = 'child_num';
        var $table;
        var $db;
        /**
         * 构造函数
         * @param string $table 表名
         * @param object $dbhanle adodb数据库教程操作句柄
         */
        function treenode($table, $dbhandle) {
                $this->db = $dbhandle;
                $this->table = $table;
                //$this->db->debug = true;
        }
        /**
         * 增加子节点
         * @param array $data 节点数据
         * @return bool
         */
        function addchild($data){
                $pid = $data[$this->f_pid];
                $sql = "select max({$this->f_s}) from {$this->table} where {$this->f_pid}=$pid";
                $data[$this->f_s] = $this->db->getone($sql) + 1;//得到待插入节点的序号
                $sql = "select * from {$this->table} where {$this->f_id} = -1";
                $rs = $this->db->execute($sql);
                $sql = $this->db->getinsertsql($rs, $data);
                $this->db->execute($sql); //插入节点数据
                if(!$this->db->affected_rows()){
                        return false;
                }
               
                $this->buildtree(1,1);        //重建节点左右值
                $this->updatelevel(1);        //生成节点级数值
                return true;
        }
        /**
         * 修改节点的数据
         * @param int $id 节点id号
         * @param array $data 节点数据
         * @return bool
         */

require_once '../../../tabs.php';
?>

 代码如下 复制代码

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html>
  <head>
    <title>jqgrid php demo</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css教程" media="screen" href="../../../themes/redmond/jquery-ui-1.7.1.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="../../../themes/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="../../../themes/ui.multiselect.css" />
    <style type="text">
        html, body {
        margin: 0;            /* remove body margin/padding */
        padding: 0;
        overflow: hidden;    /* remove scroll bars on browser window */
        font-size: 75%;
        }
    </style>
    <script src="../../../网页特效/jquery.网页特效" type="text/网页特效"></script>
    <script src="../../../js/i18n/grid.locale-en.js" type="text/网页特效"></script>
    <script type="text/javascript">
    $.jgrid.no_legacy_api = true;
    $.jgrid.usejson = true;
    </script>
    <script src="../../../js/jquery.jqgrid.min.js" type="text/javascript"></script>
    <script src="../../../js/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
  </head>
  <body>
      <div>
          <?php include ("grid.php");?>
      </div>
      <br/>
      <?php tabs(array("grid.php"));?>
   </body>
</html>

php代码

<?php
require_once '../../../jq-config.php';
// include the jqgrid class
require_once abspath."php/jqgrid.php";
// include the driver class
require_once abspath."php/jqgridpdo.php";
// connection to the server
$conn = new pdo(db_dsn,db_user,db_password);
// tell the db that we use utf-8
$conn->query("set names utf8");

// create the jqgrid instance
$grid = new jqgridrender($conn);
// write the sql query
$grid->selectcommand = 'select orderid, orderdate, customerid, freight, shipname from longorders';
// set the ouput format to json
$grid->datatype = 'json';
// let the grid create the model
$grid->setcolmodel();
// set the url from where we obtain the data
$grid->seturl('grid.php');
$grid->optimizesearch = true;
// set some grid options
$grid->setgridoptions(array("rownum"=>100,"sortname"=>"orderid","height"=>150));
// change some property of the field(s)
$grid->setcolproperty("orderdate", array(
    "formatter"=>"date",
    "formatoptions"=>array("srcformat"=>"y-m-d h:i:s","newformat"=>"m/d/y"),
    "search"=>false
    )
);
// enable toolbar searching
$grid->toolbarfilter = true;
$grid->setfilteroptions(array("stringresult"=>true));
// enjoy
$grid->rendergrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>

 

php常用正则表达式函数 我们这里面很多中正则表达式代码,包括有判断中文正则,数字字母正则,字符正则表达试,数字正则表达试,邮箱正则表达式,电话号码正则表达试,手机号码正则表达试,邮编正则表达试,/url正则表达试等哦。
php教程常用正则表达式函数
我们这里面很多中正则表达式代码,包括有判断中文正则,数字字母正则,字符正则表达试,数字正则表达试,邮箱正则表达式,电话号码正则表达试,手机号码正则表达试,邮编正则表达试,/url正则表达试等哦。
*/
 function funcchinese($str,$num1='',$num2='')//判断中文正则
 {
  if($num1!='' and $num2!=''){
   return (preg_match("/^([x81-xfe][x40-xfe]){".$num1.",".$num2."}$/",$str))?true:false;
  }else{
   return (!eregi("[^x80-xff]","$str"))?true:false;
  }
 }
 
 function funcstrnum($str,$num1='',$num2='') //数字字母正则
 {
  if($num1!='' and $num2!=''){
   return (preg_match("/^[^0-9a-za-z_@!.-]{".$num1.",".$num2."}$/",$str))?true:false;
  }else{
   return (preg_match("/^[^0-9a-za-z_@!.-]/",$str))?true:false;
  }  
 }
 // 常用的正则表达试
 
 function funcstr($str,$num1='',$num2='') //字符正则表达试
 {
  if($num1!='' and $num2!=''){
   return (preg_match("/^[a-za-z]{".$num1.",".$num2."}$/",$str))?true:false;
  }else{
   return (preg_match("/^[a-za-z]/",$str))?true:false;
  }  
 }
 
 function funcnum($str,$num1='',$num2='')//数字正则表达试
 {
  if($num1!='' and $num2!=''){
   return (preg_match("/^[0-9]{".$num1.",".$num2."}$/",$str))?true:false;
  }else{
   return (preg_match("/^[0-9]/",$str))?true:false;
  }
 }
 
 function funccard($str)//
 {
  return (preg_match('/(^([d]{15}|[d]{18}|[d]{17}x)$)/',$str))?true:false;
 }
 
 function funcemail($str)//邮箱正则表达式
 {
  return (preg_match('/^[_.0-9a-z-a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$str))?true:false;
 }
 
 function funcphone($str)//电话号码正则表达试
 {
  return (preg_match("/^(((d{3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,8}$/",$str))?true:false;
 }    
 
 function funcmtel($str)//手机号码正则表达试
 {
  return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true:false;
 } 
 
 function funczip($str)//邮编正则表达试
 {
  return (preg_match("/^[0-9]d{5}$/",$str))?true:false;
 } 
 
 function funcurl($str)//url正则表达试
 {
  return (preg_match("/^http://[a-za-z0-9]+.[a-za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$/",$str))?true:false;
 } 

  

 代码如下 复制代码

function bigendian2int($byte_word, $signed = false) { 
 
  $int_value = 0; 
 
  $byte_wordlen = strlen($byte_word); 
 
  for ($i = 0; $i < $byte_wordlen; $i++) 
 
  { 
 
  $int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i)); 
 
  } 
 
  if ($signed) 
 
  { 
 
  $sign_mask_bit = 0x80 << (8 * ($byte_wordlen - 1)); 
 
  if ($int_value & $sign_mask_bit) 
 
  { 
 
  $int_value = 0 - ($int_value & ($sign_mask_bit - 1)); 
 
  } 
 
  } 
 
  return $int_value; 
 
  } 
 
  function gettime($name){ 
 
  if(!file_exists($name)){ 
 
  return; 
 
  } 
 
  $flv_data_length=filesize($name); 
 
  $fp = @fopen($name, 'rb'); 
 
  $flv_header = fread($fp, 5); 
 
  fseek($fp, 5, seek_set); 
 
  $frame_size_data_length =bigendian2int(fread($fp, 4)); 
 
  $flv_header_frame_length = 9; 
 
  if ($frame_size_data_length > $flv_header_frame_length) { 
 
  fseek($fp, $frame_size_data_length - $flv_header_frame_length, seek_cur); 
 
  } 
 
  $duration = 0; 
 
  while ((ftell($fp) + 1) < $flv_data_length) { 
 
  $this_tag_header = fread($fp, 16); 
 
  $data_length = bigendian2int(substr($this_tag_header, 5, 3)); 
 
  $timestamp = bigendian2int(substr($this_tag_header, 8, 3)); 
 
  $next_offset = ftell($fp) - 1 + $data_length; 
 
  if ($timestamp > $duration) { 
 
  $duration = $timestamp; 
 
  } 
 
  fseek($fp, $next_offset, seek_set); 
 
  } 
 
  fclose($fp); 
 
  return $duration; 
 
  } 
 
  function fn($time){ 
 
  $num = $time; 
 
  $sec = intval($num / 1000); 
 
  $h = intval($sec / 3600); 

  $m = intval(($sec % 3600) / 60); 
 
  $s = intval(($sec % 60 )); 
 
  $tm = $h . ':' . $m . ':' . $s ; 
 
  return $tm; 
 
  }   
  echo gettime("27729.flv");//显示数字时间如236722   
  echo fn(236722); //显示时间格式0:03:56 

[!--infotagslink--]

相关文章