What are the potential security risks of storing passwords in plaintext in a database in PHP?

Storing passwords in plaintext in a database in PHP poses a significant security risk as it exposes user credentials to potential breaches. To mitigate this risk, passwords should be securely hashed before being stored in the database. This way, even if the database is compromised, the actual passwords cannot be easily accessed.

// Hashing password before storing in the database
$password = 'user_password';
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Storing hashed password in the database
// $sql = "INSERT INTO users (username, password) VALUES ('$username', '$hashed_password')";