In the provided code examples, what are some best practices for securely handling user login information and database queries in PHP?

To securely handle user login information and database queries in PHP, it is important to use prepared statements to prevent SQL injection attacks. Additionally, passwords should be hashed using a strong hashing algorithm like bcrypt before storing them in the database. It is also recommended to use HTTPS to encrypt data transmission between the client and server. Example code snippet for securely handling user login information and database queries in PHP:

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare a SQL statement with placeholders for user input
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");

// Bind the user input to the placeholders
$stmt->bindParam(':username', $_POST['username']);

// Execute the prepared statement
$stmt->execute();

// Fetch the user data
$user = $stmt->fetch();

// Verify the password using password_verify function
if ($user && password_verify($_POST['password'], $user['password'])) {
    // User login successful
    echo "Login successful";
} else {
    // User login failed
    echo "Login failed";
}