What are the potential pitfalls of using mysql_fetch_array() in PHP?

Using mysql_fetch_array() in PHP can be problematic because it fetches a row as both an associative array and an indexed array, which can lead to confusion and errors in your code. It's recommended to use mysqli_fetch_assoc() instead, which fetches a row as an associative array only. This way, you can access the data using meaningful keys without the risk of accidentally accessing it using numerical indexes.

// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query the database
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Fetch rows as associative arrays
while ($row = mysqli_fetch_assoc($result)) {
    // Access data using meaningful keys
    echo $row['column_name'];
}

// Close the connection
mysqli_close($connection);