Skip to content

Instantly share code, notes, and snippets.

@wowdyaln
Last active September 11, 2018 07:42
Show Gist options
  • Save wowdyaln/ae14953e15a7d31e81f8431f04676d03 to your computer and use it in GitHub Desktop.
Save wowdyaln/ae14953e15a7d31e81f8431f04676d03 to your computer and use it in GitHub Desktop.
code snippet for question
<?
// ... ...
$conn->autocommit(FALSE);
$conn->begin_transaction();
for ($i=0; $i < count($users); $i++){
$user = $users[$i];
$nickname = $nicknames[ mt_rand(0, count($nicknames)-1 )];
$password = password_hash('123', PASSWORD_DEFAULT);
$createUser = "INSERT INTO `users` (`id`, `username`, `nickname`, `password`) VALUES (NULL, '{$user}', '{$nickname}', '{$password}') ";
if ($conn->query($createUser)) {
echo "good! create a user: '$user'. <br> ";
} else {
echo " Error: {$conn->error} :
sql: {$createUser} ";
}
}
$conn->commit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment