skymvc网站测试之mysql数据生成
程序员文章站
2022-05-09 13:39:20
...
跳至
[1]
[全屏预览]
$v){ unset($_SESSION[$k]); } } $this->onIncrement(); } public function getNum($table){ //设置表所需要的记录数 $cf=array( "article"=>500000, "test"=>300000, "test2"=>300000, ); if(!isset($cf[$table])){ return 300000; }else{ return $cf[$table]; } } public function onAutoDelete(){ set_time_limit(0); ob_implicit_flush(true); $res=M("article")->query("show tables"); $data=M("article")->fetch_array(PDO::FETCH_NUM); $this->loadClass("spider"); if($data){ $uk=0; foreach($data as $k=>$t){ $tables[]=$t[0]; $urls[$uk][]="http://".$_SERVER['HTTP_HOST']."/index.php?m=test_mysql&a=delete&table=".str_replace(TABLE_PRE,"",$t[0]); if($k%$this->maxThreads==($this->maxThreads-1)){ $uk++; } } echo "删除开始
"; echo ' '; foreach($urls as $k=>$us){ echo "第".$k."部分
"; flush(); @ob_flush(); $this->spider->start($us,function($data){ echo $data['url']."
".$data['content']."
"; flush(); @ob_flush(); },600); } } echo "本次删结束
"; flush(); @ob_flush(); echo ""; } public function onDelete(){ $table=get('table','h'); M($table)->query("delete from ".table($table)." where 1=1 limit 50000"); echo "delete $table success"; } /*更新自增id*/ public function onIncrement(){ $res=M("article")->query("show tables"); $data=M("article")->fetch_array(PDO::FETCH_NUM); if($data){ foreach($data as $k=>$t){ $table=str_replace(TABLE_PRE,"",$t[0]); M($table)->query("ALTER TABLE `sky_".$table."` AUTO_INCREMENT=1;"); } } echo "update increment"; } public function onAutoInsert(){ set_time_limit(0); ob_implicit_flush(true); $res=M("article")->query("show tables"); $data=M("article")->fetch_array(PDO::FETCH_NUM); $tables=array(); if($data){ $uk=0; foreach($data as $k=>$t){ $tables[]=$t[0]; $urls[$uk][]="http://".$_SERVER['HTTP_HOST']."/index.php?m=test_mysql&a=insert&table=".str_replace(TABLE_PRE,"",$t[0]); if($k%$this->maxThreads==($this->maxThreads-1)){ $uk++; } } $this->loadClass("spider"); echo "开始
"; echo ' '; foreach($urls as $k=>$us){ echo "第".$k."部分
"; flush(); @ob_flush(); $this->spider->start($us,function($data){ echo $data['url']."
".$data['content']."
"; flush(); @ob_flush(); },600); } echo "结束
"; flush(); @ob_flush(); } echo ""; } public function onInsert($table=''){ $inauto=true; if(!$table){ set_time_limit(0); $inauto=false; } $table=$table?$table:get('table','h'); if(!$table){ $table="article"; } $fields=$this->getFIelds($table); //为什么只执行到266 百思不得其解 $jnum=$this->getNum($table); for($j=0;$jmaxrow;$j++){ $rscount=M($table)->selectOne(array( "fields"=>" count(1)" )); if($rscount>$jnum){ echo $table."测试数据已经够了
"; break; } if(!inauto){ echo "正在插入第".$j."千条
"; flush(); @ob_flush(); ob_clean(); } $data=array(); for($i=0;$idbPost($table); } $sql=" insert into ".table($table)."(".implode(",",$fields).") values "; foreach($data as $k=>$v){ if($k>0){ $sql.=","; } $sql.="("._implode($v).")"; } $sql.=";"; M($table)->query($sql); unset($data); unset($sql); } echo "success"; } public function getFIelds($table){ $fields=M($table)->getFields(); foreach($fields as $k=>$v){ if($k==0) continue; $data[]=$v['Field']; } return $data; } public function dbPost($table,$msg=''){ if(isset($_SESSION["field_".$table])){ $fields=$_SESSION["field_".$table]; }else{ $fields=M($table)->getFields(); $_SESSION["field_".$table]=$fields; } $msg=$msg?$msg:"skymvc是".date("Ymdhis")."最贴心的".date("Ymdhis")."php开发框架,快来使用吧!"; $data=array(); $gid=$this->getId($table); foreach($fields as $k=>$v){ if($k==0) continue; if(preg_match("/tinyint/i",$v['Type'])){ $data[$v['Field']]=rand(0,3); }elseif(preg_match("/int/i",$v['Type'])){ if($v['Field']=='dateline'){ $data[$v['Field']]=time(); }else{ $data[$v['Field']]=$gid; } }elseif(preg_match("/decimal/i",$v['Type'])){ $data[$v['Field']]=rand(1,100000); }elseif(preg_match("/datetime/i",$v['Type']) ){ $data[$v['Field']]=date("Y-m-d H:i:s"); }elseif($v['Field']=='bstatus'){ $data[$v['Field']]=1; }else{ $data[$v['Field']]=$msg; } } return $data; } public function getId($table){ if(!isset($_SESSION["autoid_$table"])){ $_SESSION["autoid_$table"]=1; }else{ $_SESSION["autoid_$table"]++; } return $_SESSION["autoid_$table"]; } } ?>