What is the potential issue with using the mysqli_fetch_row function in PHP queries?

Using the mysqli_fetch_row function in PHP queries can be problematic because it returns an enumerated array, making it difficult to access the data by column name. To solve this issue, you can use the mysqli_fetch_assoc function instead, which returns an associative array with column names as keys.

// Connect to the database
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Execute the query
$result = $conn->query("SELECT * FROM table");

// Fetch data using mysqli_fetch_assoc
while ($row = $result->fetch_assoc()) {
    // Access data by column name
    echo $row['column_name'];
}

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