How can PEAR-DB classes be integrated into a PHP script for database queries?

To integrate PEAR-DB classes into a PHP script for database queries, you need to include the necessary PEAR-DB files and create a database connection using the PEAR::DB class. You can then execute queries using the PEAR::DB query methods.

<?php
require_once 'DB.php';

$dsn = 'mysql://username:password@localhost/database_name';
$options = array(
    'debug' => 2,
    'result_buffering' => false,
);

$db = DB::connect($dsn, $options);

if (PEAR::isError($db)) {
    die($db->getMessage());
}

$sql = 'SELECT * FROM table_name';
$res = $db->query($sql);

if (PEAR::isError($res)) {
    die($res->getMessage());
}

while ($row = $res->fetchRow()) {
    // Process each row
}

$db->disconnect();
?>