$conn = mysqli_connect("localhost", "username", "password", "mydb"); $result = $conn->query("SELECT name, age from people"); $row = $result->fetch_row(); echo "Name: ".$row[0].", Age: ".$row[1];
$conn = new PDO("mysql:host=localhost;dbname=mydb", "username", "password"); $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?"); $stmt->execute([$username]); $row = $stmt->fetch(PDO::FETCH_NUM); echo "Username: ".$row[0].", Email: ".$row[1];In this example, we use the fetch_row function in conjunction with PDO to retrieve the username and email of a user from the "users" table based on their username. The fetch_row function is part of the mysqli and PDO packages, which are used for connecting to and querying databases in PHP.