How can one retrieve data from a database using PHP without relying on the mysqli_result() function and instead utilizing fetch_... methods?

When retrieving data from a database using PHP, you can use the fetch_... methods provided by the PDO extension instead of relying on the mysqli_result() function. This allows for more flexibility and control over how data is fetched from the database.

// Connect to the database using PDO
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

// Prepare a SQL statement
$stmt = $pdo->prepare("SELECT * FROM my_table");

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

// Fetch data using fetch() method
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    // Process the retrieved data
    echo $row['column_name'] . "<br>";
}