$sql2 ="UPDATE table1,table2 SET table2.password2 = ".password_hash(."table1.password1".,PASSWORD_DEFAULT)." WHERE table1.username = table2.username";
I am trying to use Php functions in Mysql update queries instead of iteration, but it doesn't seem to work. Please let me know if there is anyway I can achieve this without iteration, if with Stored procedures I can, please give a small example as I have never made a stored procedure before, thanks in advance
The below code is working good for you :) .
$sql2 ="UPDATE table1,table2 SET table2.password2 = '".password_hash("table1.password1",PASSWORD_DEFAULT) ."' WHERE table1.username = table2.username";
Try With This Below Query:
"UPDATE table2 SET table2.password2 = (SELECT '".password_hash("table1.password1",PASSWORD_DEFAULT) ."'from table1 WHERE table1.username = table2.username)"
You are missing single quote, You can try like this
$pass = password_hash("table1.password1",PASSWORD_DEFAULT);
$sql2 ="UPDATE table1,table2 SET table2.password2 = '$pass' WHERE table1.username = table2.username";