$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password'); $username = 'john'; $new_password = 'password1234'; $stmt = $pdo->prepare("UPDATE users SET password=:password WHERE username=:username"); $stmt->execute(array(':password' => $new_password, ':username' => $username));
$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password'); $username = 'john'; $new_password = password_hash('password1234', PASSWORD_DEFAULT); $stmt = $pdo->prepare("UPDATE users SET password=:password WHERE username=:username"); $stmt->execute(array(':password' => $new_password, ':username' => $username));Both of these examples use PDO to connect to a MySQL database and update the password for the user 'john'. The first example sets the password directly as plain text, while the second example uses the built-in PHP function password_hash to hash the password before setting it in the database. As set_password is not a native PHP function, it cannot be determined which package library might be used.