title: Continually try to insert random unique values into table
body: <p>So, I've got a function that generates a random number in base 62, and I would like to attempt to insert a random unique number of length 7 into the table. I originally had the rows auto-increment as the values were input, but that involved a lot of inserting, selecting, and then updating the rows. Here's the new code so far that didn't work:</p>
  
  <pre><code>do {
      if (isset($query)) { mysqli_stmt_close($query); }
      $query = mysqli_prepare($connection, "INSERT INTO table1 value1=?");
      mysqli_stmt_bind_param($query, 's', rand_64(7));
  } while (!mysqli_stmt_execute($query));
  mysqli_stmt_close($query);
  </code></pre>
  
  <p>My question is: can something like this be achieved, or would it be better to generate the random numbers, try a SELECT statement, and if the returned rows == 0, stop looping and insert the values?</p>
  
  <p>Edit: I should note that it properly inserts the values if the value is unique (i.e. not already in the table), but it fails to insert if the value already exists.</p>
  
  <p>Thanks very much. :)</p>