What potential pitfalls should beginners be aware of when trying to read data from a MySQL table using PHP?

Beginners should be aware of potential SQL injection attacks when reading data from a MySQL table using PHP. To prevent this, they should always use prepared statements with bound parameters to sanitize user input.

// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Prepare SQL statement with bound parameters
$stmt = $mysqli->prepare("SELECT * FROM table WHERE column = ?");
$stmt->bind_param("s", $value);

// Set parameter values and execute query
$value = $_GET['input'];
$stmt->execute();

// Fetch results
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    // Process data
}

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