Monday, December 26, 2011

Database Programming MySQL and Perl DBI Program Clients


Database Programming MySQL and Perl DBI Randy Julian Lilly Research Laboratories Program Clients dbms MySQL interface DBI PERL CLIENT 1 Perl DBI/DBD Interfaces DBI is the generic interface which relies on a database specific driver: DBD Must install the mysql DBD driver to use the DBI interface with MySQL PPM>install DBD::mysql DBI: An Object Oriented Module… Uses the Perl Object-Oriented syntax for calls and access to return values: my $dbh = DBI->connect ( $dsn, $user_name, $password, { RaiseError => 1, PrintError => 0 } ); 2 Naming Conventions DBI Handle Variable Names Name Meaning $dbh A handle to a database object $sth A handle to a statement (query) object $fh A handle to an open file $h A generic handle – depends on context DBI Non-Handle Variable Names Name Meaning $rc Return code from true/false operations $rv Return code from “int” operations $rows Return code from ops than return row count @ary Array (list) returned from a query Some DBI member functions ->connect() connect to a database ->prepare() setup a query ->execute() perform a query that returns a result set ->do() perform a query that returns row count ->finish() complete a partial query ->disconnect() disconnect from the database 3 Simple Example: dump_atom.pl


Website: miner.chem.purdue.edu | Filesize: 160kb
No of Page(s): 15
download: ‘http://miner.chem.purdue.edu/Lectures/Lecture24.pdf