$query = "SELECT * FROM users"; $result = $dbh->GetQueryResult($query); foreach ($result as $row) { echo $row['username'] . "
"; }
$query = "SELECT * FROM products WHERE category = 'electronics'"; $result = $dbconn->GetQueryResult($query); $num_rows = count($result); echo "Found " . $num_rows . " products in the electronics category.";This code executes a SQL query to fetch all products that belong to the 'electronics' category from a table named 'products'. The number of rows returned is counted and displayed as a message to the user. This example is using a package library named "DatabaseInterface". It is assumed that the $dbconn variable has been previously instantiated with a connection to the database.