// 对应字段 key-新,value-旧
$fields = array(
'user_id' =>'user_id',
'user_name' =>'name',
'password' =>'password',
'salt' =>'salt',
'email' =>'email',
'grade' =>'type',
'head_photo' =>'head',
'last_login_time' =>'last_time',
'last_login_ip' =>'last_ip'
);
// 原数据
$user = new maUser();
$data = $user->getAll( implode(',', $fields) );
// 需要处理的字段
foreach( $data as $f){
$f['head'] = json_decode($f['head']);
$f['head'] = str_replace('.jpg', '', $f['head'][0]->n);
$fieldStr = array();
foreach( $fields as $name ){
$fieldStr[] = "'".$f[$name]."'";
}
$fieldStr = implode(',', $fieldStr);
$sql[] = "($fieldStr)";
}
// 写入新表
$newFields = array_keys($fields);
$newFields = implode(',', $newFields);
$sql = "insert into user_account({$newFields}) values" . implode(',', $sql);
pr($sql,1);
重构-旧表导入新表数据
最新推荐文章于 2022-05-26 10:14:43 发布