数据库批量写入测试数据方法

二级会员 站长
发表于技术杂文分类
该代码需要基于hadsky v8运行:

<?php $submit = input('get.submit/d'); if ($submit) { for ($i = 0; $i < 10000; $i++) { table('read')->insert([ 'uid' => 1, 'sortid' => 1, 'title' => CreateRandomString(30), 'content' => CreateRandomString(1000), 'del' => mt_rand(0, 100) > 30 ? 0 : 1, ]); } v8Success('ok'); } g('htmlcode.output', ' <input id="count"><button id="submit" type="button">提交</button> <script> $("#submit").on("click",function(){ var s = Date.parse(new Date())/1000; var z = Cnum($("#count").val()); var a = function(count){ count--; if(count<0){ var s2 =Date.parse(new Date())/1000-s; alert("已完成"+z+"w条写入,花费"+s2+"秒"); return false; } $.getJSON("index.php",{ c:"cs", submit:1 },function(rd){ console.log(rd); if(rd["code"]){ a(count); } }); } a(z); }); </script> ');

登录 分类