<div class="codetitle"><a style="CURSOR: pointer" data="59611" class="copybut" id="copybut59611" onclick="doCopy('code59611')"> 代码如下:<div class="codebody" id="code59611"> //分库分表算法 function calc_hash_db($u,$s = 4) { $h = sprintf("%u",crc32($u)); $h1 = intval(fmod($h,$s)); return $h1; } for($i=1;$i<100;$i++) { echo calc_hash_db($i); echo " "; } function calc_hash_tbl($u,$n = 256,$m = 16) { $h = sprintf("%u",crc32($u)); $h1 = intval($h / $n); $h2 = $h1 % $n; $h3 = base_convert($h2,10,$m); $h4 = sprintf("%02s",$h3); return $h4; }
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|