If you want to do sharding, at some point you will need to decide which shard to target. Here is a simple function to assign the data to a particular shard based on a key (usually identifier of the row)
Here is a simple function to get the shard based on the key and the number of shards available
<?php
function getShard($key,$nbShards) {
$num = substr(base_convert(sha1($key), 16, 10),4,6);
return $num%$nbShards;
}
?>