You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

29 lines
811 B

  1. <?php
  2. //生成lottery code,http://wx.zhizhuchuxing.com/wechat/Api/insertCode.php?code=10000&type=1
  3. require_once '../Common/Config.php';
  4. $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
  5. $codeRange=isset($_GET['code'])?$_GET['code']:10;
  6. $type=isset($_GET['type'])?$_GET['type']:1;
  7. $arr=range(1,$codeRange);
  8. shuffle($arr);
  9. $success=array(0,0);
  10. $sql="insert into lottery_code values";
  11. $end=end($arr);
  12. foreach($arr as $k=>$v){
  13. if($k %1000 ==0){
  14. $sql=rtrim($sql,",");
  15. $result=$pdo->exec($sql);
  16. //$errinfo=$pdo->errorInfo();
  17. $sql="insert into lottery_code values(".$v.",".$type."),";
  18. }else if($v==$end){
  19. $sql.="(".$v.",".$type."),";
  20. $sql=rtrim($sql,",");
  21. $result=$pdo->exec($sql);
  22. }else{
  23. $sql.="(".$v.",".$type."),";
  24. }
  25. }
  26. echo "成功生成";
  27. ?>