DBMaker Starting Guides

The starting guide for Perl

1. Installation

  • Perl
    If you have not installed Perl on your system:
    • On Unix/Linux:
      Obtain perl source file from Perl HOME and build it.
    • On Win9x/NT:
      Obtain perl binary from ActiveState and install it.
  • DBI
    If you have not installed DBI on your system:
    • Obtain DBI source from DBI web site and install it.
      Example:
      $ tar zxvf DBI-1.13.tar.gz
      Or 
      $ gunzip DBI-1.13.tar.gz
      $ tar xvf DBI-1.13.tar
      
    • After you unpack it, change directory to DBI-1.13 and install it:
      $ cd DBI-1.13
      $ perl Makefile.PL
      $ make
      $ make test
      $ make install   
      
    • After installing DBI module, you can reference the Perl DBI specification by:
      $ perldoc DBI
      
  • DBD-DBMaker
    • Copy DBD-DBMaker driver to your local directory and unpack it.
      For example: if current DBD-DBMaker version is 0.14, you can do as the following:
      $ cp ~dbmaker/3.5/driver/Perl/DBD-DBMaker-0.14.tar.gz .
      
      # Unpack the DBD-DBMaker package:
      $ tar zxvf DBD-DBMaker-0.14.tar.gz
      Or 
      $ gunzip DBD-DBMaker-0.14.tar.gz
      $ tar xvf DBD-DBMaker-0.14.tar
      
    • Change directory to DBD-DBMaker-0.14.
      $ cd DBD-DBMaker-0.14
      
    • Make sure to read README file included in the package before building DBD-DBMaker.
      $ perl Makefile.PL
      $ make
      $ make test
      $ make install
      
    • For DBMaker related information about perl DBI methods, please reference it by:
      $ perldoc DBD::DBMaker
      

2. Your first Perl Program

Here we illustrate a very simple Perl script for retrieving data in the database test.

Paste the following Perl code to a file, and name it with the extension pl (for example: test.pl)

use strict;
use DBI;
 
##conncet to DB test
my $dbh=DBI->connect( "dbi:DBMaker:test","SYSADM","",
                    )||die "Database connection not made:$DBI::err
 
my $sth=$dbh->prepare("select * from t1");
$sth->execute();
 
###fetch result from t1
while(my @ary=$sth->fetchrow_array) {
      print "c1 = $ary[0], c2 = $ary[1]\n";
}
 
$sth->finish();
$dbh->disconnect();

3. Testing your first Perl Program

  1. Set your environment variable DBMAKER to where you create the "test" database or where you put dmconfig.ini by:
    Example:
    If you put your dmconfig.ini in ~/config directory.
    sh,bash:
        $ export DBMAKER=~/config
    csh, tcsh:
        $ setenv DBMAKER ~/config
    
    Or you can copy DBMaker config file dmconfig.ini from where you create "test" database to where you put your perl program.
    Example:
    If you put your perl program in ~/test
    $ cp dmconfig.ini ~/test
    
  2. Run the perl script
    $ perl test.pl
    
  3. The result will be as follows:
    c1 = 1, c2 = dbmaker   
    c1 = 2, c2 = database  
    

4. More Information

  1. DBD::DBMaker for Perl DBI document
  2. How to handle BLOB field with Perl
  3. DBMaker Perl samples
  4. Perl DBI starting guide (in Chinese)
  5. Perl Related sites

[ Back To Manuals Index ]

Copyright 2002 SYSCOM Computer Engineering Co. All rights reserved.