Hey,
i found this on google and i think it might help you..
<?php
/**
Topic: Making first steps with PEAR DB abstraction.
Tutorial: Urs Gehrig <urs_at_circle_dot_ch>
Date: 9-3-2001
/
/**
Get the PEAR classes
/
require_once("C:/PHP/pear/PEAR.php");
require_once("C:/PHP/pear/DB.php");
require_once("C:/PHP/pear/DB/mysql.php");
/**
Make the connection to
- a "mysql" type database
- on the database server "localhost"
- calling the database named "localhost"
*/
$dbh = DB::connect("mysql://localhost/localhost");
if (DB::isError($dbh)) {
die("connect.inc: ".$dbh->getMessage());
}
/**
This script prints "skip" unless:
- the mysql extension is built-in or loadable, AND
- there is a database called "test" accessible
with no username/password, AND
- we have create/drop privileges on the entire "test"
database
*/
if (!extension_loaded("mysql")) {
$dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so";
@dl("mysql$dlext");
}
if (!extension_loaded("mysql")) {
die("skip\n");
}
$conn = @mysql_connect("localhost");
if (!is_resource($conn)) {
die("skip\n");
}
if (!mysql_select_db("localhost", $conn)) {
die("skip\n");
}
/**
Drop and create table
*/
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
$dbh->query("DROP TABLE phptest");
$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)");
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
/**
Perform queries
*/
print("<html><pre>");
print("-- EVALUATED --\n");
$dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')");
$dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')");
printf("%d after insert\n", $dbh->affectedRows());
$dbh->query("SELECT * FROM phptest");
printf("%d after select\n", $dbh->affectedRows());
$dbh->query("DELETE FROM phptest WHERE b = 'test'");
printf("%d after delete\n", $dbh->affectedRows());
$dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')");
$dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')");
$dbh->query("DELETE FROM phptest");
printf("%d after delete all (optimize=%s)\n", $dbh->affectedRows(), $dbh->getOption("optimize"));
$dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')");
$dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')");
$dbh->setOption("optimize", "portability");
$dbh->query("DELETE FROM phptest");
printf("%d after delete all (optimize=%s)\n", $dbh->affectedRows(), $dbh->getOption("optimize"));
/**
The above output should correspond to the
output printed below
*/
print("
-- EXPECTED --
1 after insert
0 after select
2 after delete
0 after delete all (optimize=performance)
2 after delete all (optimize=portability)
");
print("</pre></html>");
?>