Running a query with PEAR::DB

Tagged:  

I found this code in nice book, "Ubuntu Linux Unleashed, 2008 Edition".
It's a basic example of how to run a sql query using PEAR::DB (in php of course).

<?php
include(“DB.php”);
$dsn = “mysql://ubuntu:alm65z@10.0.0.1/dentists”;
$conn = DB::connect($dsn);
if (DB::isError($conn))
{
  echo $conn->getMessage() . “\n”;
}
else
{
  echo “Connected successfully!\n”;
  $result = $conn->query(“SELECT ID, Name FROM patients;”);
  while ($result->fetchInto($row, DB_FETCHMODE_ASSOC))
  {
    extract($row, EXTR_PREFIX_ALL, ‘pat’);
    echo “$pat_ID is $pat_Name\n”;
  }
  $result->free();
  $conn->disconnect();
}
?>