Running a query with PEAR::DB
By liviu - Posted on May 14th, 2009
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();
}
?>
Bookmark/Search this post with:
- liviu's blog
- Login or register to post comments
Delicious
Digg
StumbleUpon
Propeller
Reddit
Magnoliacom
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket