dongre9937 2017-08-18 00:33
浏览 32

too long

I'm trying to generate a unique hash for all the users in the Database; Here is my code:

<?php
include("php/connect.php");


$sql = "SELECT id FROM user";


while ($id = mysqli_fetch_assoc(mysqli_query($conn, $sql))) {

    $new_hash = md5(uniqid(rand(), TRUE));

    $sql2 = "INSERT INTO user (hash) VALUE ('$new_hash') WHERE id = $id['id']";
    mysqli_query($conn, $sql2);


}

?>

Every time I run it, I get the following error:

Fatal error: Maximum execution time of 30 seconds exceeded in
  • 写回答

2条回答 默认 最新

  • doucheng2210 2017-08-18 01:03
    关注

    Regarding this query:

    $sql2 = "INSERT INTO user (hash) VALUE ('$new_hash') WHERE id = $id['id']";
    

    INSERT doesn't use a WHERE clause, UPDATE does, as does INSERT ... ON DUPLICATE KEY UPDATE.

    However, I don't know why you're wanting to do that. Using a column set to AUTO_INCREMENT should be ample to have a unique id.

    Yet, if that is what you want to do, then you will need to use one of the methods shown above.

    I.e.:

    if(!$sql2){ 
    
      echo "Error: " . mysqli_error($conn);
    
    }
    
    评论

报告相同问题?