PHP batch add or update mysql data table plugin

Plug-in function:

Add or update regular mysql data tables in batches. For example, the data format of a table is as follows:

If it is manually modified in the database, or modified in the background of the website, it will be very cumbersome, and it is very convenient and quick to use the plug-in!

Plugin page:

1. First, you need two encapsulated mysql database base classes

common.php

<?php/*** php显示指定长度的字符串,超出长度以省略号(...)填补尾部显示* @ str 字符串* @ len 指定长度**/function cutSubstr($str,$len=30){ if (strlen($str)>$len) {	$str=substr($str,0,$len) . '...'; } return $str;}/*** php自动识别字符集编码并转换为目标编码(UTF-8)的方法* @ data     需要转换的字符集* @ encoding 目标编码**/function autoChangeCode($data,$encoding = 'utf-8'){  if( !empty($data) ){        $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;       if( $fileType != $encoding){         $data = mb_convert_encoding($data ,$encoding , $fileType);       }     }     return $data;    }/数据库操作///function dbinsert($table, $type){    $dbin = mysql_query("INSERT INTO `{$table}` {$type}");    return $dbin;}function dbquery($table, $type){    $dbq = mysql_query("SELECT * FROM `{$table}` {$type}");    while ($rdb = mysql_fetch_array($dbq)) {        $rdbq[] = $rdb;    }    return $rdbq;}function dbquerysun($table, $type){    $dbqsun = mysql_query("SELECT count(id) FROM `{$table}` {$type}");    $rdbsun = mysql_fetch_array($dbqsun);    return $rdbsun;}function dbdel($table, $type){    $dbdel = mysql_query("delete FROM `{$table}` where {$type}");    return $rdel;}function queryall($table, $type){    $sql = mysql_query("SELECT * FROM `{$table}` {$type}");    $row = mysql_fetch_array($sql);    return $row;}function upalldt($table, $type){    $dbup = mysql_query("UPDATE `{$table}` SET {$type}");    return $dbup;}function getall($sql) {    $query=mysql_query($sql);    if($query) {        $temp=array();        while($res=mysql_fetch_assoc($query)) {            $temp[]=$res;        }        return $temp;    }    else{    return false;    }}function getone($sql) {    $query=mysql_query($sql);    if($query) {        $res=mysql_fetch_assoc($query);        return $res;    }    else{        return false;    }}?>

conn.php

<?php这里信息根据自己的实际情况可以修改//$localhost = "127.0.0.1";   //服务器地址,一般为localhost$user      = "root";        //服务器MYSQL登陆用户名$password  = "root";        //服务器的MYSQL登陆密码$database  = "data_db";     //你使用的数据库 /以下内容,非专业人员请不要修改,避免错误$conn = @mysql_connect("$localhost","$user","$password") or die ("数据库连接出错,请检查");@mysql_select_db("$database",$conn) or die ("数据库表不存在或者未连接");mysql_query("set names gbk"); //使用GBK中文件编码,防止出错 ?>

Two, plug-in addOrUpdate.php

<?php/** * 本插件用于批量添加或更新mysql数据表 */date_default_timezone_set('PRC'); //默认时区session_start();error_reporting(0); include ("config/common.php");include ("config/conn.php"); if (isset($_POST['submit'])) {	//表	$table=$_POST['table'];	//字段1	$attr1=$_POST['attr1'];	//字段2	$attr2=$_POST['attr2'];	//总期数	$total=$_POST['total'];	//间隔时间	$IntervalTime=$_POST['IntervalTime'];	//第一期时间	$firstlTime=$_POST['firstlTime'];	//类型	$type=$_POST['type']; 	//时间增加	$plus='+'.$IntervalTime.' minute';	//字符串转时间	$kj=strtotime($firstlTime);	$fp=strtotime('-5 second',$kj);	//查询表中是否存在该类型数据	$typeid=getone("select id from ".$table." where type='".$type."' limit 1");	if(empty($typeid)||$typeid==""){		//批量添加		for ($i=1; $i<=$total; $i++) {				if($i!=1){	 				$kj=strtotime($plus,$kj);				$fp=strtotime('-5 second',$kj);			}			$kjTime=date("H:i:s",$kj);			$fpTime=date("H:i:s",$fp);			$insert_sql="(`type`, `actionNo`, `actionTime`, `stopTime`) values ('$type', '$i', '$kjTime', '$fpTime')";			$ref=dbinsert($table,$insert_sql);			if($ref==1){				$msg="成功";			}else{				$msg="失败";			}			echo "第 $i 期开奖时间: $kjTime ,封盘时间:$fpTime 添加结果:$msg<br>";		}	}else{		//批量更新		for ($i=1; $i<=$total; $i++) {				if($i!=1){	 				$kj=strtotime($plus,$kj);				$fp=strtotime('-5 second',$kj);			}			$kjTime=date("H:i:s",$kj);			$fpTime=date("H:i:s",$fp);			$update_sql="actionTime='$kjTime',stopTime='$fpTime' where type='$type' and actionNo='$i' ";			$ref=upalldt($table,$update_sql);			if($ref==1){				$msg="成功";			}else{				$msg="失败";			}			echo "第 $i 期开奖时间: $kjTime ,封盘时间:$fpTime 更新结果:$msg<br>";		}	}	}	?><!DOCTYPE html><html><head><title>批量添加或更新mysql数据表</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, minimal-ui"><meta name="format-detection" content="telephone=no">	</head><body> <form action=""  method="post"><table width="100%" border="0" cellpadding="5" cellspacing="5"><tbody><tr><td width="35%" height="40" align="right">表名:</td><td height="40"><input type="text" name="table" value="jcb_data_time" placeholder="请输入要更新的表名"></td></tr><tr><td height="40" align="right">字段1:</td><td height="40"><input type="text" name="attr1" value="actionTime"></td></tr><tr><td height="40" align="right">字段2:</td><td height="40"><input type="text" name="attr2" value="stopTime"></td></tr><tr><td height="40" align="right">总期数:</td><td height="40"><input type="text" name="total" value="180"></td></tr><tr><td height="40" align="right">间隔时间:</td><td height="40"><input type="text" name="IntervalTime" value="5"></td></tr><tr><td height="40" align="right">第一期时间:</td><td height="40"><input type="text" name="firstlTime" value="13:05:00"></td></tr><tr><td height="40" align="right">类型:</td><td height="40"><input type="text" name="type" value="7"></td></tr><tr><td height="40"></td><td height="40"><input type="submit" name= "submit" value="立即执行">&nbsp;&nbsp;<input type="reset" value="重置">&nbsp;&nbsp;<input type="button" onclick="location.href='/addOrUpdate.php'" value="刷新页面"></td></tr></tbody></table></form></body></html>