Jump to content
php.lv forumi

Kļūda par UUID_SHORT


senters

Recommended Posts

Uz localhosta nemet wārningu, uz produkcijas servera met.

 

Neliela f-ja unikāla key uzģenerēšanai:

function generateUniqueKeyShort() {
        $sql = mysql_query("select UUID_SHORT()");
        $row = mysql_fetch_assoc($sql);
        return $row['UUID_SHORT()'];
    }
 

Kļūda - Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in [..]

 

* Līdzīgi tiek ģenerēts arī garāks key par kuru nemet kļūdu.

    function generateUniqueKey() {
        $sql = mysql_query("select UUID()");
        $row = mysql_fetch_array($sql);
        return $row['UUID()'];
    }
 
Edited by senters
Link to comment
Share on other sites

uzmetu šādi:

function generateUniqueKeyShortWithPhp() {
        //set the random id length
        $random_id_length = 10;


        //generate a random id encrypt it and store it in $rnd_id
        $rnd_id = crypt(uniqid(rand(),1));


        //to remove any slashes that might have come
        $rnd_id = strip_tags(stripslashes($rnd_id));


        //Removing any . or / and reversing the string
        $rnd_id = str_replace(".","",$rnd_id);
        $rnd_id = strrev(str_replace("/","",$rnd_id));


        //finally I take the first 10 characters from the $rnd_id
        $rnd_id = substr($rnd_id,0,$random_id_length);


        return $rnd_id;
    }
 
Edited by senters
Link to comment
Share on other sites

Ko neviens vairs savu custom kodu netaisa, garlaicīgi :P

 

function genUniqueId( $length=20 ) {
    $s = 'asdfghkqwer(*&^%$!@#1234345675679';
    $key = '';
    while ( strlen( $key ) < $length )
        $key .= $s[rand( 0, strlen( $s ) - 1 )];
    return $key;
}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...