I need a function which will generate 128bit string and check database for does it unique, if unique it will return the string or generate another...

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your PHP question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your PHP question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer

I need a function which will generate 128bit string and check database for does it unique, if unique it will return the string or generate another one, until it is a unique string.

Posted
Albert Shohez
Programmer

Hi, I made this example for you, hope it will work for you.

function unigqueid($n) { // here $n= how much length call unigqueid(16) for 128 bit,1byte=8bit
    $str='';
    for ($i=0; $i<$n; $i++) {
        $str.=base_convert(mt_rand(1,36),10,36);
    }

    $link = mysql_connect("localhost", "mysql_user", "mysql_password");
    mysql_select_db("database", $link);

    $result = mysql_query("SELECT id FROM table where id='".$str."'", $link);
    $num_rows = mysql_num_rows($result);

    if(  $num_rows>0)
    {
         function unigqueid($n);
    }
    return $str;
}
Posted
Customer

wow thanks, you saved my time.

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More PHP Questions...

Ask Your PHP Question & Get An Answer Now!