2001-01-08 14:30perl, dbi and dbd::informix perl, apache, dbi and dbd::informix jonathan leffler...

35
2001-01-08 1 4:30 Perl, DBI and DBD: :Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

Post on 18-Dec-2015

241 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30 Perl, DBI and DBD::Informix

Perl, Apache, DBI and DBD::Informix

Jonathan LefflerArchitect, Foundation Engineering

Page 2: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 2

AgendaAgenda

] PerlPerl

] DBIDBI

] DBD::InformixDBD::Informix

] ApacheApache

] mod_perlmod_perl

] Questions and answersQuestions and answers

] PerlPerl

] DBIDBI

] DBD::InformixDBD::Informix

] ApacheApache

] mod_perlmod_perl

] Questions and answersQuestions and answers

Page 3: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 3

Perl - Practical Extraction and Report LanguagePerl - Practical Extraction and Report Language

] Originally written by Larry WallOriginally written by Larry Wall» Version 1.0 in 1987Version 1.0 in 1987» Version 4.0 in 1991 under GPL and Artistic LicenseVersion 4.0 in 1991 under GPL and Artistic License» Version 5.0 in 1994Version 5.0 in 1994

] Very widely availableVery widely available] Current stable versions:Current stable versions:

» 5.6.15.6.1» 5.005_03 (with optional thread support)5.005_03 (with optional thread support)» 5.004_04 (without thread support)5.004_04 (without thread support)

] Obtain via CPANObtain via CPAN» Comprehensive Perl Archive NetworkComprehensive Perl Archive Network» http://www.cpan.org/http://www.cpan.org/

] Originally written by Larry WallOriginally written by Larry Wall» Version 1.0 in 1987Version 1.0 in 1987» Version 4.0 in 1991 under GPL and Artistic LicenseVersion 4.0 in 1991 under GPL and Artistic License» Version 5.0 in 1994Version 5.0 in 1994

] Very widely availableVery widely available] Current stable versions:Current stable versions:

» 5.6.15.6.1» 5.005_03 (with optional thread support)5.005_03 (with optional thread support)» 5.004_04 (without thread support)5.004_04 (without thread support)

] Obtain via CPANObtain via CPAN» Comprehensive Perl Archive NetworkComprehensive Perl Archive Network» http://www.cpan.org/http://www.cpan.org/

Page 4: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 4

PerlPerl

] Script LanguageScript Language

» Does not require compilationDoes not require compilation

] Complex looking codeComplex looking code

] Can be incredibly terseCan be incredibly terse

] Can be quite legibleCan be quite legible

] Excellent at string handlingExcellent at string handling

] Excellent access to operating systemExcellent access to operating system

] Script LanguageScript Language

» Does not require compilationDoes not require compilation

] Complex looking codeComplex looking code

] Can be incredibly terseCan be incredibly terse

] Can be quite legibleCan be quite legible

] Excellent at string handlingExcellent at string handling

] Excellent access to operating systemExcellent access to operating system

Page 5: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 5

Remove RCS Keyword MarkersRemove RCS Keyword Markers

#!/usr/bin/perl -wp#!/usr/bin/perl -wp

s/\$([A-Z][a-z]+|RCSfile): ([^\$]+) \$/$2/g;s/\$([A-Z][a-z]+|RCSfile): ([^\$]+) \$/$2/g;

] TMTOWTDITMTOWTDI» There’s more than one way to do it!There’s more than one way to do it!» (Yes, you could use (Yes, you could use sedsed for this) for this)

perl -wp -e ’s%\$\w+: ([^\$]+) \$%$1%go;’ $*perl -wp -e ’s%\$\w+: ([^\$]+) \$%$1%go;’ $*

#!/usr/bin/perl -wp#!/usr/bin/perl -wp

s/\$([A-Z][a-z]+|RCSfile): ([^\$]+) \$/$2/g;s/\$([A-Z][a-z]+|RCSfile): ([^\$]+) \$/$2/g;

] TMTOWTDITMTOWTDI» There’s more than one way to do it!There’s more than one way to do it!» (Yes, you could use (Yes, you could use sedsed for this) for this)

perl -wp -e ’s%\$\w+: ([^\$]+) \$%$1%go;’ $*perl -wp -e ’s%\$\w+: ([^\$]+) \$%$1%go;’ $*

Page 6: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 6

Remove HTML Markup

#/usr/bin/perl -wp

s/<param>[^<>]+<\/param>//go;

s/<[^>]+>//go;

s/\&quot;/"/go;

s/\&lt;/</go;

s/\&gt;/>/go;

s/\&amp;/&/go;

s/\&nbsp;/ /go;

Page 7: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 7

#!/usr/bin/perl# @(#)$Id: rename.pl,v 1.1 1992/01/05 22:33:47 jl Exp $# Rename files using a Perl substitute command

($op = shift) || die "Usage: $0 perlexpr [filenames]\n";if (!@ARGV) {

@ARGV = <STDIN>;chop(@ARGV);

}for (@ARGV){

$was = $_;eval $op;die $@ if $@;rename($was, $_) unless $was eq $_;

}

File Renaming

Page 8: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 8

Perl Database InterfacePerl Database Interface

] DBI written by Tim BunceDBI written by Tim Bunce

] Standard way to access databases with PerlStandard way to access databases with Perl

] Many database drivers availableMany database drivers available

» Including ODBCIncluding ODBC

» And DB2And DB2

» And OracleAnd Oracle

» And, of course, InformixAnd, of course, Informix

» And many othersAnd many others

] Current version 1.15Current version 1.15

] Using Perl and a database? Use DBI!Using Perl and a database? Use DBI!

] DBI written by Tim BunceDBI written by Tim Bunce

] Standard way to access databases with PerlStandard way to access databases with Perl

] Many database drivers availableMany database drivers available

» Including ODBCIncluding ODBC

» And DB2And DB2

» And OracleAnd Oracle

» And, of course, InformixAnd, of course, Informix

» And many othersAnd many others

] Current version 1.15Current version 1.15

] Using Perl and a database? Use DBI!Using Perl and a database? Use DBI!

Page 9: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 9

The Cheetah BookThe Cheetah Book

] The ‘bible’ for Perl DBIThe ‘bible’ for Perl DBI

] Authors:Authors:

» Alligator Descartes Alligator Descartes

» Tim BunceTim Bunce

] O’Reilly, February 2000O’Reilly, February 2000

] ISBN 1-56592-699-4ISBN 1-56592-699-4

] http://www.oreilly.com/http://www.oreilly.com/

] The ‘bible’ for Perl DBIThe ‘bible’ for Perl DBI

] Authors:Authors:

» Alligator Descartes Alligator Descartes

» Tim BunceTim Bunce

] O’Reilly, February 2000O’Reilly, February 2000

] ISBN 1-56592-699-4ISBN 1-56592-699-4

] http://www.oreilly.com/http://www.oreilly.com/

Page 10: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 10

DBI - Database HandlesDBI - Database Handles

] Load DBILoad DBI» use DBI;use DBI;

] Create database handlesCreate database handles» $dbh = DBI->connect(‘DBI:Informix:stores7’);$dbh = DBI->connect(‘DBI:Informix:stores7’);

] Database methodsDatabase methods» $dbh->do(‘DELETE FROM Customer’);$dbh->do(‘DELETE FROM Customer’);

] Transaction controlTransaction control» $dbh->rollback;$dbh->rollback;» $dbh->commit;$dbh->commit;

] DisconnectDisconnect» $dbh->disconnect;$dbh->disconnect;

] Load DBILoad DBI» use DBI;use DBI;

] Create database handlesCreate database handles» $dbh = DBI->connect(‘DBI:Informix:stores7’);$dbh = DBI->connect(‘DBI:Informix:stores7’);

] Database methodsDatabase methods» $dbh->do(‘DELETE FROM Customer’);$dbh->do(‘DELETE FROM Customer’);

] Transaction controlTransaction control» $dbh->rollback;$dbh->rollback;» $dbh->commit;$dbh->commit;

] DisconnectDisconnect» $dbh->disconnect;$dbh->disconnect;

Page 11: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 11

DBI - Statement HandlesDBI - Statement Handles

] Create statement handlesCreate statement handles» $sth = $dbh->prepare(qq{ DELETE FROM Customer $sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE ‘%$name%’ AND ZipCode IS WHERE Lname LIKE ‘%$name%’ AND ZipCode IS NULL });NULL });

] Statements can be executedStatements can be executed» $sth->execute();$sth->execute();

] Statement handles can be releasedStatement handles can be released

» ImplicitlyImplicitly» Statement handle goes out of scopeStatement handle goes out of scope

» ExplicitlyExplicitly» undef $sth;undef $sth;

] Create statement handlesCreate statement handles» $sth = $dbh->prepare(qq{ DELETE FROM Customer $sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE ‘%$name%’ AND ZipCode IS WHERE Lname LIKE ‘%$name%’ AND ZipCode IS NULL });NULL });

] Statements can be executedStatements can be executed» $sth->execute();$sth->execute();

] Statement handles can be releasedStatement handles can be released

» ImplicitlyImplicitly» Statement handle goes out of scopeStatement handle goes out of scope

» ExplicitlyExplicitly» undef $sth;undef $sth;

Page 12: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 12

DBI - Handling SELECTDBI - Handling SELECT

] Statement handles are used for SELECT tooStatement handles are used for SELECT too» $sth = $dbh->prepare(qq% SELECT * FROM Customer $sth = $dbh->prepare(qq% SELECT * FROM Customer WHERE Fname = ? AND Lname = ? ORDER BY Lname, WHERE Fname = ? AND Lname = ? ORDER BY Lname, Fname%);Fname%);

» $sth->execute($firstname, $surname);$sth->execute($firstname, $surname);» @results = $sth->fetchall_arrayref;@results = $sth->fetchall_arrayref;

» ……process resultsprocess results» print print $results[$rownum][$colnum]$results[$rownum][$colnum], etc, etc

» undef $sth;undef $sth;

] SELECT is fairly simpleSELECT is fairly simple

] Statement handles are used for SELECT tooStatement handles are used for SELECT too» $sth = $dbh->prepare(qq% SELECT * FROM Customer $sth = $dbh->prepare(qq% SELECT * FROM Customer WHERE Fname = ? AND Lname = ? ORDER BY Lname, WHERE Fname = ? AND Lname = ? ORDER BY Lname, Fname%);Fname%);

» $sth->execute($firstname, $surname);$sth->execute($firstname, $surname);» @results = $sth->fetchall_arrayref;@results = $sth->fetchall_arrayref;

» ……process resultsprocess results» print print $results[$rownum][$colnum]$results[$rownum][$colnum], etc, etc

» undef $sth;undef $sth;

] SELECT is fairly simpleSELECT is fairly simple

Page 13: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 13

DBI - Handling SELECTDBI - Handling SELECT

] Many ways to fetch rowsMany ways to fetch rows» $sth->fetchrow_array$sth->fetchrow_array» $sth->fetchrow_hashref$sth->fetchrow_hashref» $sth->fetchrow_arrayref$sth->fetchrow_arrayref» $sth->fetchall_arrayref$sth->fetchall_arrayref

] Also utility methodsAlso utility methods» $dbh->selectrow_array$dbh->selectrow_array» $dbh->selectall_arrayref$dbh->selectall_arrayref

] Many ways to fetch rowsMany ways to fetch rows» $sth->fetchrow_array$sth->fetchrow_array» $sth->fetchrow_hashref$sth->fetchrow_hashref» $sth->fetchrow_arrayref$sth->fetchrow_arrayref» $sth->fetchall_arrayref$sth->fetchall_arrayref

] Also utility methodsAlso utility methods» $dbh->selectrow_array$dbh->selectrow_array» $dbh->selectall_arrayref$dbh->selectall_arrayref

Page 14: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 14

DBD::Informix - at lastDBD::Informix - at last

] Using DBD::Informix is using DBIUsing DBD::Informix is using DBI

» All the examples work with DBD::InformixAll the examples work with DBD::Informix

] Current version is 1.00.PC1Current version is 1.00.PC1

] Building DBD::Informix is easyBuilding DBD::Informix is easy

» Requires working ESQL/C 5.00 or later (eg ClientSDK)Requires working ESQL/C 5.00 or later (eg ClientSDK)» ANSI C compiler (code uses prototypes)ANSI C compiler (code uses prototypes)» Test database with DBA privilegesTest database with DBA privileges» Perl version 5.004 or laterPerl version 5.004 or later

» 5.005_03 or 5.6.1 strongly recommended5.005_03 or 5.6.1 strongly recommended

» DBI version 1.02 or laterDBI version 1.02 or later» Version 1.14 or later strongly recommendedVersion 1.14 or later strongly recommended

] Using DBD::Informix is using DBIUsing DBD::Informix is using DBI

» All the examples work with DBD::InformixAll the examples work with DBD::Informix

] Current version is 1.00.PC1Current version is 1.00.PC1

] Building DBD::Informix is easyBuilding DBD::Informix is easy

» Requires working ESQL/C 5.00 or later (eg ClientSDK)Requires working ESQL/C 5.00 or later (eg ClientSDK)» ANSI C compiler (code uses prototypes)ANSI C compiler (code uses prototypes)» Test database with DBA privilegesTest database with DBA privileges» Perl version 5.004 or laterPerl version 5.004 or later

» 5.005_03 or 5.6.1 strongly recommended5.005_03 or 5.6.1 strongly recommended

» DBI version 1.02 or laterDBI version 1.02 or later» Version 1.14 or later strongly recommendedVersion 1.14 or later strongly recommended

Page 15: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 15

Installing DBD::InformixInstalling DBD::Informix

] Download software from CPANDownload software from CPAN» cd DBD-Informix-1.00.PC1cd DBD-Informix-1.00.PC1» more READMEmore README» perl Makefile.PLperl Makefile.PL» makemake» make testmake test» make installmake install

» Have fun!Have fun!

] Same rules apply to all Perl modulesSame rules apply to all Perl modules

] Building Perl modules is easy!Building Perl modules is easy!

] Download software from CPANDownload software from CPAN» cd DBD-Informix-1.00.PC1cd DBD-Informix-1.00.PC1» more READMEmore README» perl Makefile.PLperl Makefile.PL» makemake» make testmake test» make installmake install

» Have fun!Have fun!

] Same rules apply to all Perl modulesSame rules apply to all Perl modules

] Building Perl modules is easy!Building Perl modules is easy!

Page 16: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 16

#! /usr/bin/perl -w

use DBI;

$dbh = DBI->connect(‘DBI:Informix:stores7’,’’,’’, {RaiseError => 1, PrintError=>1});

$sth = $dbh->prepare(q%SELECT Fname, Lname, Phone

FROM Customer WHERE Customer_num = ? %);

$sth->execute(106);

$ref = $sth->fetchall_arrayref();

for $row (@$ref) {

print “Name: $$row[0] $$row[1], Phone: $$row[2]\n”;

}

$dbh->disconnect;

DBD::Informix - example

Error Checking Automated

Page 17: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 17

DBD::Informix & AutoCommitDBD::Informix & AutoCommit

] AutoCommit is on by defaultAutoCommit is on by default

» To comply with DBI requirementsTo comply with DBI requirements

» Cannot be unset on unlogged databasesCannot be unset on unlogged databases

» Simulates MODE ANSI on logged databasesSimulates MODE ANSI on logged databases

» Explicit BEGIN WORK is possibleExplicit BEGIN WORK is possible» $dbh->do(‘begin work’);$dbh->do(‘begin work’);

] $dbh->{AutoCommit} = 0;$dbh->{AutoCommit} = 0;

] $dbh = DBI->connect(‘DBI:Informix:stores7’, $dbh = DBI->connect(‘DBI:Informix:stores7’, ‘’, ‘’, { AutoCommit => 0 });‘’, ‘’, { AutoCommit => 0 });

] AutoCommit is on by defaultAutoCommit is on by default

» To comply with DBI requirementsTo comply with DBI requirements

» Cannot be unset on unlogged databasesCannot be unset on unlogged databases

» Simulates MODE ANSI on logged databasesSimulates MODE ANSI on logged databases

» Explicit BEGIN WORK is possibleExplicit BEGIN WORK is possible» $dbh->do(‘begin work’);$dbh->do(‘begin work’);

] $dbh->{AutoCommit} = 0;$dbh->{AutoCommit} = 0;

] $dbh = DBI->connect(‘DBI:Informix:stores7’, $dbh = DBI->connect(‘DBI:Informix:stores7’, ‘’, ‘’, { AutoCommit => 0 });‘’, ‘’, { AutoCommit => 0 });

Page 18: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 18

Standard DBI InformationStandard DBI Information

] Standard database attributesStandard database attributes» $dbh->{Driver}$dbh->{Driver}» $dbh->{AutoCommit}$dbh->{AutoCommit}» $dbh->{PrintError}$dbh->{PrintError}» $dbh->{RaiseError}$dbh->{RaiseError}» $dbh->{ChopBlanks}$dbh->{ChopBlanks}

] There are others, too.There are others, too.

] Standard database attributesStandard database attributes» $dbh->{Driver}$dbh->{Driver}» $dbh->{AutoCommit}$dbh->{AutoCommit}» $dbh->{PrintError}$dbh->{PrintError}» $dbh->{RaiseError}$dbh->{RaiseError}» $dbh->{ChopBlanks}$dbh->{ChopBlanks}

] There are others, too.There are others, too.

Page 19: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 19

Standard DBI InformationStandard DBI Information

] Standard statement attributesStandard statement attributes» $sth->{Statement}$sth->{Statement}» $sth->{CursorName}$sth->{CursorName}» $sth->{NUM_OF_FIELDS}$sth->{NUM_OF_FIELDS}» $sth->{NUM_OF_PARAMS}$sth->{NUM_OF_PARAMS}» $sth->{NAME}$sth->{NAME}» $sth->{TYPE}$sth->{TYPE}» $sth->{NULLABLE}$sth->{NULLABLE}

] Standard statement attributesStandard statement attributes» $sth->{Statement}$sth->{Statement}» $sth->{CursorName}$sth->{CursorName}» $sth->{NUM_OF_FIELDS}$sth->{NUM_OF_FIELDS}» $sth->{NUM_OF_PARAMS}$sth->{NUM_OF_PARAMS}» $sth->{NAME}$sth->{NAME}» $sth->{TYPE}$sth->{TYPE}» $sth->{NULLABLE}$sth->{NULLABLE}

Page 20: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 20

Standard DBI InformationStandard DBI Information

] Standard handle attributesStandard handle attributes» $h->err$h->err» $h->errstr$h->errstr» $h->state$h->state

] Standard handle methodsStandard handle methods» $h->trace($trace_level)$h->trace($trace_level)» $h->trace_msg(“message”)$h->trace_msg(“message”)

] Standard handle attributesStandard handle attributes» $h->err$h->err» $h->errstr$h->errstr» $h->state$h->state

] Standard handle methodsStandard handle methods» $h->trace($trace_level)$h->trace($trace_level)» $h->trace_msg(“message”)$h->trace_msg(“message”)

Page 21: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 21

Informix-only InformationInformix-only Information

] SQLCA is availableSQLCA is available» $sth->{ix_sqlcode}$sth->{ix_sqlcode}» $sth->{ix_sqlerrd}$sth->{ix_sqlerrd} - an array - an array» $sth->{ix_sqlerrm}$sth->{ix_sqlerrm}» $sth->{ix_sqlerrp}$sth->{ix_sqlerrp}» $sth->{ix_sqlwarn}$sth->{ix_sqlwarn} - an array - an array

] SQLCA is availableSQLCA is available» $sth->{ix_sqlcode}$sth->{ix_sqlcode}» $sth->{ix_sqlerrd}$sth->{ix_sqlerrd} - an array - an array» $sth->{ix_sqlerrm}$sth->{ix_sqlerrm}» $sth->{ix_sqlerrp}$sth->{ix_sqlerrp}» $sth->{ix_sqlwarn}$sth->{ix_sqlwarn} - an array - an array

Page 22: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 22

Informix-only InformationInformix-only Information

] Non-standard attributesNon-standard attributes» $dbh->{ix_InformixOnline}$dbh->{ix_InformixOnline}» $dbh->{ix_LoggedDatabase}$dbh->{ix_LoggedDatabase}» $dbh->{ix_ModeAnsiDatabase}$dbh->{ix_ModeAnsiDatabase}» $dbh->{ix_InTransaction}$dbh->{ix_InTransaction}» $dbh->{ix_ConnectionName}$dbh->{ix_ConnectionName}

] Standard attributeStandard attribute» $dbh->{Name}$dbh->{Name} — database name— database name

] Non-standard attributesNon-standard attributes» $dbh->{ix_InformixOnline}$dbh->{ix_InformixOnline}» $dbh->{ix_LoggedDatabase}$dbh->{ix_LoggedDatabase}» $dbh->{ix_ModeAnsiDatabase}$dbh->{ix_ModeAnsiDatabase}» $dbh->{ix_InTransaction}$dbh->{ix_InTransaction}» $dbh->{ix_ConnectionName}$dbh->{ix_ConnectionName}

] Standard attributeStandard attribute» $dbh->{Name}$dbh->{Name} — database name— database name

Page 23: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 23

Informix-only InformationInformix-only Information

] Non-standard attributesNon-standard attributes» $drh->{ix_ProductVersion}$drh->{ix_ProductVersion}

» a version number for ESQL/Ca version number for ESQL/C

» $drh->{ix_ProductName}$drh->{ix_ProductName}» $drh->{ix_MultipleConnections}$drh->{ix_MultipleConnections}» $drh->{ix_ActiveConnections}$drh->{ix_ActiveConnections}» $drh->{ix_CurrentConnection}$drh->{ix_CurrentConnection}» $drh->{ix_ServerVersion}$drh->{ix_ServerVersion}

» a version number for the database servera version number for the database server

] All these attributes can also be found via the All these attributes can also be found via the database handle, $dbhdatabase handle, $dbh

] Non-standard attributesNon-standard attributes» $drh->{ix_ProductVersion}$drh->{ix_ProductVersion}

» a version number for ESQL/Ca version number for ESQL/C

» $drh->{ix_ProductName}$drh->{ix_ProductName}» $drh->{ix_MultipleConnections}$drh->{ix_MultipleConnections}» $drh->{ix_ActiveConnections}$drh->{ix_ActiveConnections}» $drh->{ix_CurrentConnection}$drh->{ix_CurrentConnection}» $drh->{ix_ServerVersion}$drh->{ix_ServerVersion}

» a version number for the database servera version number for the database server

] All these attributes can also be found via the All these attributes can also be found via the database handle, $dbhdatabase handle, $dbh

Page 24: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 24

Informix-only InformationInformix-only Information

] Non-standard attributesNon-standard attributes» $sth->{ix_NativeTypeName}$sth->{ix_NativeTypeName}» $sth->{ix_ColType}$sth->{ix_ColType}» $sth->{ix_ColLength}$sth->{ix_ColLength}

] Non-standard attributesNon-standard attributes» $sth->{ix_NativeTypeName}$sth->{ix_NativeTypeName}» $sth->{ix_ColType}$sth->{ix_ColType}» $sth->{ix_ColLength}$sth->{ix_ColLength}

Page 25: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 25

DBD::InformixDBD::Informix

] Known LimitationsKnown Limitations

» Not yet fully aware of 9.x collection types or UDTsNot yet fully aware of 9.x collection types or UDTs

» Doesn’t handle blobs in UPDATE statementsDoesn’t handle blobs in UPDATE statements» Coded in DBD::Informix 1.01.PC1Coded in DBD::Informix 1.01.PC1» $sth->bind_param(3, $blobval, {ix_type=>IX_TEXT})

» No support for No support for bind_param_inoutbind_param_inout method method

] Version 1.10.PC1 is an official Informix productVersion 1.10.PC1 is an official Informix product

» Officially “Informix Database Driver for Perl”Officially “Informix Database Driver for Perl”

» The support channel is the mailing listThe support channel is the mailing list» [email protected]@informix.com

] Known LimitationsKnown Limitations

» Not yet fully aware of 9.x collection types or UDTsNot yet fully aware of 9.x collection types or UDTs

» Doesn’t handle blobs in UPDATE statementsDoesn’t handle blobs in UPDATE statements» Coded in DBD::Informix 1.01.PC1Coded in DBD::Informix 1.01.PC1» $sth->bind_param(3, $blobval, {ix_type=>IX_TEXT})

» No support for No support for bind_param_inoutbind_param_inout method method

] Version 1.10.PC1 is an official Informix productVersion 1.10.PC1 is an official Informix product

» Officially “Informix Database Driver for Perl”Officially “Informix Database Driver for Perl”

» The support channel is the mailing listThe support channel is the mailing list» [email protected]@informix.com

Page 26: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 26

DBD::Informix DocumentsDBD::Informix Documents

] Primary ReferencesPrimary References

» Pre-installPre-install» README fileREADME file

» Informix.Licence fileInformix.Licence file

» Post-installPost-install» perldoc DBIperldoc DBI

» perldoc DBD::Informixperldoc DBD::Informix

] BooksBooks

» Programming Perl, 3rd EditionProgramming Perl, 3rd Edition

» Programming the Perl DBIProgramming the Perl DBI

] Primary ReferencesPrimary References

» Pre-installPre-install» README fileREADME file

» Informix.Licence fileInformix.Licence file

» Post-installPost-install» perldoc DBIperldoc DBI

» perldoc DBD::Informixperldoc DBD::Informix

] BooksBooks

» Programming Perl, 3rd EditionProgramming Perl, 3rd Edition

» Programming the Perl DBIProgramming the Perl DBI

Page 27: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 27

DBD::Informix - Web SitesDBD::Informix - Web Sites

] Use CPAN to obtain the softwareUse CPAN to obtain the software

» http://www.cpan.orghttp://www.cpan.org

] DBI web sitesDBI web sites

» http://www.symbolstone.org/technology/perl/DBIhttp://www.symbolstone.org/technology/perl/DBI

» http://www.perl.org/dbi-lists.htmlhttp://www.perl.org/dbi-lists.html» Sign up for [email protected] mailing listSign up for [email protected] mailing list

» http://eskimo.tamu.edu/~jbaker/dbi-examples.htmlhttp://eskimo.tamu.edu/~jbaker/dbi-examples.html

] Help yourself - join the mailing list!Help yourself - join the mailing list!

] Use CPAN to obtain the softwareUse CPAN to obtain the software

» http://www.cpan.orghttp://www.cpan.org

] DBI web sitesDBI web sites

» http://www.symbolstone.org/technology/perl/DBIhttp://www.symbolstone.org/technology/perl/DBI

» http://www.perl.org/dbi-lists.htmlhttp://www.perl.org/dbi-lists.html» Sign up for [email protected] mailing listSign up for [email protected] mailing list

» http://eskimo.tamu.edu/~jbaker/dbi-examples.htmlhttp://eskimo.tamu.edu/~jbaker/dbi-examples.html

] Help yourself - join the mailing list!Help yourself - join the mailing list!

Page 28: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 28

Apache Apache

] Apache Web ServerApache Web Server

» Most widely used web serverMost widely used web server

» Version 1.3.19 Version 1.3.19 » unless there’s a new version this weekunless there’s a new version this week

] Modular structureModular structure

» Allows special purpose modules to be addedAllows special purpose modules to be added» mod_jserv - Java Servermod_jserv - Java Server

» mod_perl - Perl Interpretermod_perl - Perl Interpreter

] Apache Web ServerApache Web Server

» Most widely used web serverMost widely used web server

» Version 1.3.19 Version 1.3.19 » unless there’s a new version this weekunless there’s a new version this week

] Modular structureModular structure

» Allows special purpose modules to be addedAllows special purpose modules to be added» mod_jserv - Java Servermod_jserv - Java Server

» mod_perl - Perl Interpretermod_perl - Perl Interpreter

Page 29: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 29

Apache, Perl and CGIApache, Perl and CGI

] CGI scripts drive the webCGI scripts drive the web

] Many of them are Perl scriptsMany of them are Perl scripts

] Most of those use the CGI moduleMost of those use the CGI module

] http://www.somewhere.com/cgi-bin/script.plhttp://www.somewhere.com/cgi-bin/script.pl

» Giveaway that there’s a Perl script in useGiveaway that there’s a Perl script in use

» Often not that easy to spotOften not that easy to spot

] Can be slow on heavily loaded serversCan be slow on heavily loaded servers

» New Perl interpreter loaded for every hitNew Perl interpreter loaded for every hit

] CGI scripts drive the webCGI scripts drive the web

] Many of them are Perl scriptsMany of them are Perl scripts

] Most of those use the CGI moduleMost of those use the CGI module

] http://www.somewhere.com/cgi-bin/script.plhttp://www.somewhere.com/cgi-bin/script.pl

» Giveaway that there’s a Perl script in useGiveaway that there’s a Perl script in use

» Often not that easy to spotOften not that easy to spot

] Can be slow on heavily loaded serversCan be slow on heavily loaded servers

» New Perl interpreter loaded for every hitNew Perl interpreter loaded for every hit

Page 30: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 30

Apache and mod_perlApache and mod_perl

] Use mod_perl version 1.24_01 or laterUse mod_perl version 1.24_01 or later

] Requires Perl 5.004 or laterRequires Perl 5.004 or later

] Can automatically download pre-requisitesCan automatically download pre-requisites

» perl -MCPAN -e ‘install Bundle::Apache’perl -MCPAN -e ‘install Bundle::Apache’

» Downloads, compiles, tests, installs softwareDownloads, compiles, tests, installs software

] Simlarly for DBI and DBD::InformixSimlarly for DBI and DBD::Informix

» perl -MCPAN -e ‘install Bundle::DBD::Informix’perl -MCPAN -e ‘install Bundle::DBD::Informix’

» You need to see this in action to believe it!You need to see this in action to believe it!

] Also consider FastCGI technologyAlso consider FastCGI technology

» http://www.fastcgi.com/http://www.fastcgi.com/

] Use mod_perl version 1.24_01 or laterUse mod_perl version 1.24_01 or later

] Requires Perl 5.004 or laterRequires Perl 5.004 or later

] Can automatically download pre-requisitesCan automatically download pre-requisites

» perl -MCPAN -e ‘install Bundle::Apache’perl -MCPAN -e ‘install Bundle::Apache’

» Downloads, compiles, tests, installs softwareDownloads, compiles, tests, installs software

] Simlarly for DBI and DBD::InformixSimlarly for DBI and DBD::Informix

» perl -MCPAN -e ‘install Bundle::DBD::Informix’perl -MCPAN -e ‘install Bundle::DBD::Informix’

» You need to see this in action to believe it!You need to see this in action to believe it!

] Also consider FastCGI technologyAlso consider FastCGI technology

» http://www.fastcgi.com/http://www.fastcgi.com/

Page 31: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 31

Much faster web service

Greased LightningGreased Lightning

] Apache with mod_perlApache with mod_perl

» Uses same CGI scriptsUses same CGI scripts» Cleaned up for multiple useCleaned up for multiple use

» Loads scripts once and reuses themLoads scripts once and reuses them

» Without starting a separate process each hitWithout starting a separate process each hit

» Can even re-use database connectionsCan even re-use database connections» Apache::DBI moduleApache::DBI module

» BUTBUT» httpd is much biggerhttpd is much bigger

] Apache with mod_perlApache with mod_perl

» Uses same CGI scriptsUses same CGI scripts» Cleaned up for multiple useCleaned up for multiple use

» Loads scripts once and reuses themLoads scripts once and reuses them

» Without starting a separate process each hitWithout starting a separate process each hit

» Can even re-use database connectionsCan even re-use database connections» Apache::DBI moduleApache::DBI module

» BUTBUT» httpd is much biggerhttpd is much bigger

Page 32: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 32

There’s a lot of it about

Apache DocumentationApache Documentation

] http://perl.apache.org/http://perl.apache.org/

] Use perldoc for mod_perl infoUse perldoc for mod_perl info

» mod_perl_trapsmod_perl_traps

» mod_perl_tuningmod_perl_tuning

» Apache::DBIApache::DBI

» cgi_to_mod_perlcgi_to_mod_perl

» CGICGI

] HOWTO for Linux at IIUG web siteHOWTO for Linux at IIUG web site

» http://www.iiug.org/http://www.iiug.org/

] http://perl.apache.org/http://perl.apache.org/

] Use perldoc for mod_perl infoUse perldoc for mod_perl info

» mod_perl_trapsmod_perl_traps

» mod_perl_tuningmod_perl_tuning

» Apache::DBIApache::DBI

» cgi_to_mod_perlcgi_to_mod_perl

» CGICGI

] HOWTO for Linux at IIUG web siteHOWTO for Linux at IIUG web site

» http://www.iiug.org/http://www.iiug.org/

Page 33: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 33

Apache and mod_javaApache and mod_java

] Apache-JservApache-Jserv

» Version 1.1.2 or laterVersion 1.1.2 or later

] Similar to Apache & PerlSimilar to Apache & Perl

] Requires JDK 1.1.x and JSDK 2.0Requires JDK 1.1.x and JSDK 2.0

] Obtain from Apache web siteObtain from Apache web site

» http://java.apache.orghttp://java.apache.org

] HOWTO in D4GL corner of IDN web siteHOWTO in D4GL corner of IDN web site

] Apache-JservApache-Jserv

» Version 1.1.2 or laterVersion 1.1.2 or later

] Similar to Apache & PerlSimilar to Apache & Perl

] Requires JDK 1.1.x and JSDK 2.0Requires JDK 1.1.x and JSDK 2.0

] Obtain from Apache web siteObtain from Apache web site

» http://java.apache.orghttp://java.apache.org

] HOWTO in D4GL corner of IDN web siteHOWTO in D4GL corner of IDN web site

Page 34: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 34

Questions and Answers

Your Turn! Your Turn! Don’t forget to check outDon’t forget to check out

http://www.iiug.org/http://www.iiug.org/

http://www.perl.com/http://www.perl.com/

http://www.apache.org/http://www.apache.org/

Thank You for ListeningThank You for Listening

Page 35: 2001-01-08 14:30Perl, DBI and DBD::Informix Perl, Apache, DBI and DBD::Informix Jonathan Leffler Architect, Foundation Engineering

2001-01-08 14:30

Perl, DBI and DBD::Informix 35

Questions and Answers