WEB DATABASE PROGRAMMING
Discuss the different ways for looping over a query result in PHP.
What are placeholders? How are they used in PHP database programming?
OBJECT AND OBJECT-RELATIONAL DATABASE
How do regular inheritance, multiple inheritance, and selective inheritance differ?
What are the main differences between designing a relational database and an object database?
XML EXTENSIBLE MARKUP LANGUAGE
What is the difference between data-centric and document-centric XML documents?
Sample Answer
Looping Over Query Results in PHP
PHP provides several methods to iterate over the results of a database query:
fetch_array()
: This method returns an array with each row of the result set. You can iterate over this array using aforeach
loop:
PHP
$result = mysqli_query($conn, "SELECT * FROM users");
while ($row = mysqli_fetch_array($result)) {
echo $row['name'] . "<br>";
}
fetch_assoc()
: This method returns an associative array with column names as keys. You can also use aforeach
loop to iterate over this:
PHP