$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id"); $stmt->execute(['id' => $id]); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$result = $mysqli->query("SELECT * FROM users WHERE id = $id"); $row = $result->fetch_assoc();In both examples, we are fetching a row of data from the users table where the ID matches a certain value. The fetch command retrieves the data from the database as an associative array, which we can then use in our PHP code. The selectRow method is a key function in most PHP database adapter libraries. It is often used in combination with other methods, such as insert, update, and delete, to perform operations on database tables.