What are the best practices for handling and storing passwords securely in PHP scripts using MySQLi?

To securely handle and store passwords in PHP scripts using MySQLi, it is recommended to use password hashing functions like password_hash() to securely hash passwords before storing them in the database. Additionally, it is important to use prepared statements to prevent SQL injection attacks when interacting with the database.

// Hash and store password securely
$password = "password123";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Prepare SQL statement
$stmt = $mysqli->prepare("INSERT INTO users (username, password) VALUES (?, ?)");
$stmt->bind_param("ss", $username, $hashed_password);

// Execute SQL statement
$stmt->execute();
$stmt->close();