senters Posted March 4, 2013 Report Share Posted March 4, 2013 (edited) 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 March 4, 2013 by senters Link to comment Share on other sites More sharing options...
daGrevis Posted March 4, 2013 Report Share Posted March 4, 2013 Kāpēc UUID tiek ģenetēts datubāzes pusē? Link to comment Share on other sites More sharing options...
senters Posted March 4, 2013 Author Report Share Posted March 4, 2013 Pieradums, man vairāk interesē kādēļ šāds error Link to comment Share on other sites More sharing options...
draugz Posted March 5, 2013 Report Share Posted March 5, 2013 Spriežot pēc warninga pieprasījums ir nepareizs :) esi drošs, ka produkcijas serverī strādā tava select UUID_SHORT() funkcija? Link to comment Share on other sites More sharing options...
senters Posted March 5, 2013 Author Report Share Posted March 5, 2013 Varbūt ir kāds labs veids kā ar php uzģenerēt unikālu ID (garumā līdz 16 simb.)? Tad nevajdzētu to darīt DB pusē Link to comment Share on other sites More sharing options...
aaxc Posted March 5, 2013 Report Share Posted March 5, 2013 uniqid ? Link to comment Share on other sites More sharing options...
senters Posted March 5, 2013 Author Report Share Posted March 5, 2013 (edited) 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 March 5, 2013 by senters Link to comment Share on other sites More sharing options...
rATRIJS Posted March 5, 2013 Report Share Posted March 5, 2013 http://php.net/manual/en/function.mcrypt-create-iv.php Link to comment Share on other sites More sharing options...
daGrevis Posted March 5, 2013 Report Share Posted March 5, 2013 Jums nav UUID bibliotēkas? :O http://vpaste.net/FfaDn Link to comment Share on other sites More sharing options...
senters Posted March 5, 2013 Author Report Share Posted March 5, 2013 paldies par atbildēm, palikšu pie savas fjas ko iemetu šeit Link to comment Share on other sites More sharing options...
senters Posted March 5, 2013 Author Report Share Posted March 5, 2013 (edited) Jums nav UUID bibliotēkas? :O http://vpaste.net/FfaDn ar UUID problēmu nebija arī uz prod.servera (godaddy), problēmas tieši ar uuid_short Edited March 5, 2013 by senters Link to comment Share on other sites More sharing options...
Kasspars Posted March 5, 2013 Report Share Posted March 5, 2013 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 More sharing options...
Recommended Posts