What are some best practices for securing PHP and MySQL access in an Android app?

Securing PHP and MySQL access in an Android app involves using best practices such as parameterized queries to prevent SQL injection attacks, implementing proper authentication and authorization mechanisms, and encrypting sensitive data during transmission. Additionally, it is recommended to use secure connection protocols like HTTPS to protect data in transit.

<?php
// Establish a secure connection to the MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Use parameterized queries to prevent SQL injection
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);

// Execute the query
$stmt->execute();
$result = $stmt->get_result();

// Close the connection
$stmt->close();
$conn->close();
?>