|
123456789101112131415161718192021222324252627282930 |
- <?php
- //生成lottery code,http://xmwxc.zhizhuchuxing.cn/wechat/Api/insertCode.php?code=10000&type=1
- require_once '../Common/Config.php';
- $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
- //$pdo = new PDO("sqlsrv:Server=127.0.0.1;Database=monitor", "sa", "123456");
- $codeRange=isset($_GET['code'])?$_GET['code']:10;
- $type=isset($_GET['type'])?$_GET['type']:1;
- $arr=range(1,$codeRange);
- shuffle($arr);
- $success=array(0,0);
- $sql="insert into lottery_code values";
- $end=end($arr);
- foreach($arr as $k=>$v){
- if($k %1000 ==0){
-
- $sql=rtrim($sql,",");
- $result=$pdo->exec($sql);
- //$errinfo=$pdo->errorInfo();
- $sql="insert into lottery_code values(".$v.",".$type."),";
-
- }else if($v==$end){
- $sql.="(".$v.",".$type."),";
- $sql=rtrim($sql,",");
- $result=$pdo->exec($sql);
- }else{
- $sql.="(".$v.",".$type."),";
- }
- }
- echo "成功生成";
- ?>
|