NAME
DBQuery - Lib of DB Query
SYNOPSIS
The following lib are provided:
- import
-
use DBQuery;
- Struct Init
-
Init mysql struct example:
my %DB = ( 'db_host' => 'web10.search.cnb.yahoo.com', 'db_user' => 'yahoo', 'db_pass' => 'yahoo', 'db_name' => 'ADCode', ); my $db = new DBQuery(\%DB);
or postgresql:
my %PQ = ( 'driver_name' => 'PgPP', 'db_host' => 'tool2.search.cnb.yahoo.com', 'db_name' => 'cnedb', 'db_user' => 'cnedb', 'db_pass' => 'cnedb', ); my $db = new DBQuery(\%PQ);
or oracle:
my %OC = ( 'driver_name' => 'oracle', 'db_host' => 'ocndb', 'db_user' => 'alibaba', 'db_pass' => 'ocndb', ); my $db = new DBQuery(\%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', ); my $db = new DBQuery(\%DB);
it yet run.
- Connect
-
Connect resource from database.
$db->connect();
You can unset the variable: %DB, %PQ or $OC, like this:
undef %PQ;
or
undef %DB;
or
undef %OC;
- Query
-
Simple query:
$db->query("select url from edb.white_black_grey where spamtype=':demote2:' limit 10;"); while (my @row = $db->fetch_array()) { print Dumper @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 Dumper $row, "\n"; }
- Disconnect
-
Release resource from database.
$db->close();
OPTIONS
Nothing because of no script.
DESCRIPTION
DBQuery
allows you to query some information from some different type databases, like mysql, postgresql and oracle, so our system need module which include DBD::mysql, DBD::PgPP and DBD::Oracle.
In furture, it'll support more and more database types if you want. You can use DBQuery
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.
$self->new()
Construct.
$self->connect()
Create a connect.
$self->close()
Close this connection.
$self->query()
Send a query.
$self->fetch_array()
Fetch and return array.
$self->fetch_arrayref()
Fetch and return reference of array.
$self->fetch_hash()
Fetch and return reference of hash.
$self->quote()
Quote some characters.
TIPS
There's some extra tips found in our own's everyday use:
- CUSTOM
-
Like php-mysql
$db->connect(); $db->query(); $db->fetch_array();
- ABSTRACT
-
One line description of the module. Will be included in PPD file.
- ABSTRACT_FROM
-
Name of the file that contains the package description. MakeMaker looks for a line in the POD matching /^($package\s-\s)(.*)/. This is typically the first line in the "=head1 NAME" section. $2 becomes the abstract.
PREREQUISITES
This module uses DBI.
INSTALLATION
If you are not soudoer or root, you need contact administrator.
perl Makefile.PL
make
make test
make install
Win32 users should replace "make" with "nmake".
SOURCE CONTROL
You can always get the latest SSH::Batch source from its public Git repository:
http://github.com/cnangel/DB/tree/master
If you have a branch for me to pull, please let me know ;)
TODO
Sqlite2 and sqlite3 will be supported.
SEE ALSO
DBI, DBD::mysql, DBD::PgPP, DBD::Oracle
COPYRIGHT AND LICENSE
This module as well as its programs are licensed under the BSD License.
Copyright (c) 2007-2008, Yahoo! China Relevance Team, Alibaba Inc. All rights reserved.
Copyright (c) 2009, Alibaba Search Center, Alibaba Inc. All rights reserved.
Copyright (C) 2009, Cnangel Li (cnangel). All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the Alibaba Search Center, Alibaba Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
AUTHOR
Cnangel (junliang.li@alibaba-inc.com)
HISTORY
Fri Jun 26 09:47:13 2009 v0.001 Build.
Mon Jun 29 10:30:10 2009 v0.002 Modify DB to DBquery.
Mon Jun 29 16:56:02 2009 v0.003 Can miss out the arg: db_host, and optimize the test.
Tue Jun 30 17:31:44 2009 v0.004 Modify the test case.
Tue Jul 07 10:19:28 2009 v0.005 Repair and pass test.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.