method newId documentation in bbn\Db

Generate a new casual id based on the max number of characters of id's column structure in the given table

Example

X::dump($db->newId('table_users', 18)); // (int) 69991701 function($table, int $min = 1) { $tab = $this->modelize($table); if (\count($tab['keys']['PRIMARY']['columns']) !== 1) { die("Error! Unique numeric primary key doesn't exist"); } if (($id_field = $tab['keys']['PRIMARY']['columns'][0]) && ($maxlength = $tab['fields'][$id_field]['maxlength'] ) && ($maxlength > 1) ) { $max = (10 ** $maxlength) - 1; if ($max >= mt_getrandmax()) { $max = mt_getrandmax(); } if (($max > $min) && ($table = $this->tfn($table, true))) { $i = 0; do { $id = random_int($min, $max); /** @todo */ /* if ( strpos($tab['fields'][$id_field]['type'], 'char') !== false ){ $id = substr(md5('bbn'.$id), 0, random_int(1, 10 ** $maxlength)); } */ $i++; } while (($i < 100) && $this->select($table, [$id_field], [$id_field => $id])); return $id; } } return null; }

Generate a new casual id based on the max number of characters of id's column structure in the given table BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.