0

I am trying to port all passwords from one value to another value (each user), so I am looking for an applicable way to port all of them in MySQL, I am basically looking to run my crypt function over all $row['password'].

currently I have a SELECT and instead of doing a seperate UPDATE I was thinking how to do this in one connection. I've written my SELECT so far and I have an array of my model.

$query = "SELECT * FROM t_user";
$result = mysqli_query($dbc,$query);
$encryption_service = new EncryptionService;

$newUserSet = [];
foreach ($result as $row){
    $row['password'] = $encryption_service->encrypt($password);
    $newUserSet[] = $row;
}

How would I update all rows for password column in one query? I'm a bit confused on how to read a balue and then invoke a function on the value in an update statement.

7
  • And the question is? Commented Jul 23, 2019 at 9:55
  • check the end of the OP, added more precise question. Commented Jul 23, 2019 at 11:33
  • Why do you make your own encrypt function? Did you try to use php's build in functions password_hash and password_verify?? Commented Jul 23, 2019 at 11:37
  • 1
    Anyway, if your function is a php function you will need to retrieve all users data, recalculate the password and then do an update. There is no way you can execute a php function inside a mysql query Commented Jul 23, 2019 at 11:39
  • Read this question stackoverflow.com/questions/4750891/… Commented Jul 23, 2019 at 11:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.