require_once('DB.php'); $db = DB::connect('mysql://user:password@localhost/database'); $results = $db->getAssoc("SELECT id, name FROM users"); print_r($results);
require_once('DB.php'); $db = DB::connect('pgsql://user:password@localhost/database'); $results = $db->getAssoc("SELECT category, count(*) FROM products GROUP BY category"); foreach ($results as $category => $count) { echo "There are $count products in the $category category.In this example, we connect to a PostgreSQL database and run an aggregate query to count the number of products in each category. The results are returned as an associative array, where the category is the key and the count is the value. We iterate over the array and print a message for each category. Overall, the DB GetAssoc function is a useful tool for retrieving and processing data from a database table in PHP. It is part of the PEAR::DB package library, which provides a simple and consistent interface for working with various types of database systems.
"; }