NAME
DB.pm - Lib of DB Query
SYNOPSIS
use DB;
OPTIONS
- Struct Init
-
Mysql example:
my %DB = ( 'db_host' => 'web10.search.cnb.yahoo.com', 'db_user' => 'yahoo', 'db_pass' => 'yahoo', 'db_name' => 'ADCode', );
my $db = new DB(\%DB);
or postgresql example:
my %PQ = ( 'driver_name' => 'PgPP', 'db_host' => 'tool2.search.cnb.yahoo.com', 'db_name' => 'cnedb', 'db_user' => 'cnedb', 'db_pass' => 'cnedb', );
or oracle example:
my %OC = ( 'driver_name' => 'oracle', 'db_host' => 'ocndb', 'db_user' => 'alibaba', 'db_pass' => 'ocndb', );
my $db = new DB(\%OC);
over this, you can use dsn for init structure.
my %DB = ( 'dsn' => 'dbi:mysql:database=testinter;host=localhost;mysql_socket=/var/lib/mysql/mysql.sock', 'db_user' => 'pca', 'db_pass' => 'pca', );
it yet run.
- Connect
-
$db->connect();
You can unset the variable: %DB, %PQ or $OC, like this:
undef %PQ; or undef %DB; or undef %OC;
- Query
-
Simple:
$db->query("select url from edb.white_black_grey where spamtype=':demote2:' limit 10;");
while (my $row = $db->fetch_array()) { print $row, "\n"; }
Common:
my $query = $db->query("select url from edb.white_black_grey where spamtype=':demote2:' limit 10;");
while (my $row = $db->fetch_array($query)) { print $row, "\n"; }
- Disconnect
-
$db->close();
DESCRIPTION
This lib will query some information from some different type databases, you can use it very expediently. so we use database easily.
This lib can use dsn which contains all connection infomation or use all single items, like db_host, db_pass etc.
AUTHOR
Cnangel (junliang.li@alibaba-inc.com)
HISTORY
Thu Nov 8 13:53:42 2007 v0.001 Build.
Wed Jan 2 14:54:48 2008 v0.002 Build and add postgresql query.
Fri Jan 18 15:31:57 2008 v0.002 Update.
Tue Jun 16 14:52:22 2009 v0.003 Build and add oracle query function.
Wed Jun 17 10:01:32 2009 v0.004 Could use uri which contains connection infomation for databases.