What are some recommended resources for learning best practices for using mysqli in PHP?

When using mysqli in PHP, it is important to follow best practices to ensure secure and efficient database interactions. Some recommended resources for learning these best practices include the official PHP documentation on mysqli, online tutorials from reputable websites like W3Schools or PHP.net, and books such as "PHP and MySQL Web Development" by Luke Welling and Laura Thomson.

// Example code snippet using mysqli prepared statements for secure database interactions
$mysqli = new mysqli("localhost", "username", "password", "database");

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

// Prepare a SQL statement
$stmt = $mysqli->prepare("SELECT id, name FROM users WHERE email = ?");

// Bind parameters
$stmt->bind_param("s", $email);

// Set parameters and execute
$email = "example@example.com";
$stmt->execute();

// Bind result variables
$stmt->bind_result($id, $name);

// Fetch results
while ($stmt->fetch()) {
    echo "ID: " . $id . " Name: " . $name . "<br>";
}

// Close statement and connection
$stmt->close();
$mysqli->close();