I'm trying to add some UUID's to my users table. I'm having a foreach loop which should generate a unique UUID for every user in my db. The problem is that every user is getting the same UUID in the db, but when I add a "echo" i see that it generates a separate UUID for every user, but that is not reflected in the db. Is PDO doing some sort of caching, as it doesn't care about that the $uuid variable is changing?
function getAllIds($db) {
$stmt = $db->query("SELECT id from users;");
$array = $stmt->fetchAll();
return $array;
}
foreach (getAllIds($db) as $ids) {
$uuid = uuid();
print "$uuid\n";
$stmt = $db->prepare("update users set user_uuid = ?");
$stmt->execute(array($uuid));
}