Download presentation
Presentation is loading. Please wait.
Published byEmery Elliott Modified over 9 years ago
1
How to using MS Access database in Perl/CGI Web Programming Wei Sun
2
Introduction ODBC stands for: ODBC stands for: Open DataBase Connectivity The ODBC standard was designed to work on any platform and has been ported to win32, unix, macintosh, os/2 and others. The ODBC standard was designed to work on any platform and has been ported to win32, unix, macintosh, os/2 and others.
3
Introduction ODBC was designed by: X/Open X/Open SQL Access Group SQL Access Group ANSI ANSI ISO ISO Microsoft Microsoft Digital Digital Sybase Sybase IBM IBM Novell Novell Oracle Oracle Lotus Lotus and others. and others.
4
Introduction ODBC Manager ODBC Manager determines what to do. ODBC Driver ODBC Driver performs actual processing. Database Access file The database file is opened by the driver and data is manipulated. Perl Program Program calls an ODBC Module. Win32:ODBC ODBC Module call the ODBC
5
Install win32::odbc module step one: (perl 5.XXX need) step one: (perl 5.XXX need) Download win32-ODBC.zip from http://www.activestate.com/PPMPackages/zips/5xx-builds- only/Win32-ODBC.zip Readme Win32-ODBC.ppd Win32-ODBC.tar.gz http://www.activestate.com/PPMPackages/zips/5xx-builds- only/Win32-ODBC.zip http://www.activestate.com/PPMPackages/zips/5xx-builds- only/Win32-ODBC.zip step two: step two: In dos windows, in the fold in which you unziped win32-odbc: ppm install Win32-ODBC.ppd or ppm install win32-odbcbeta -- location=http://www.roth.net/perl/packages (if you use new version perl)
6
Build a Database and Configure in ODBC Step one Step one creat a access file and add some tables and data in: (file name is test.mdb, table name is Address)
7
Build a Database and Configure in ODBC step two step two Data Source Name Database Information Userid Password Connection Information User DSN only can be accessed by who create it. If you want the database to be used by network user, configure it in System DSN You can add/change DSN name as you wish, not must be "MS Access 97 Database". a) open Start->Setting->Contrl Panel->data source(ODBC), select MS Access Database in User DSN.
8
Build a Database and Configure in ODBC b)select your database file: b)select your database file: In the Advanced, you can set the ID and password to access the database.
9
Test your database in Perl/CGI program A) load odbc module A) load odbc module#!perl use Win32::ODBC;
10
Test your database in Perl/CGI program B) Connect database B) Connect database $DSN = "MS Access Database"; #data base name if (!( $db = new Win32::ODBC($DSN) )){ #$db is handle,ID and PW can be input here print "connect to database failed. "; print "Error:".win32::ODBC::Error()." \n"; exit;} else{ print "connected to database (connected number", $db->Connection(), ") "; }
11
Test your database in Perl/CGI program C)show the table list in the database C)show the table list in the database @tables = $db->TableList; print @tables; D) select a table(submit a query) D) select a table(submit a query) if (! $db->Sql(" SELECT * FROM [address] Where age>=20 ") ){ //this is SQL language @FieldNames = $db->FieldNames(); }
12
Test your database in Perl/CGI program E)insert, update, delete records E)insert, update, delete records #insert $sqlinsert = “ INSERT INTO address VALUES ('Euler', 'euler@21cn.com', 28, '021-345689') "; #updata $sqlupdate = “ UPDATE address SET age = age+10 "; #del $sqldelete = “ DELETE FROM address WHERE name='jimtyan' ";
13
Test your database in Perl/CGI program 3.6 close the database 3.6 close the database$db->Close();
14
Test your database in Perl/CGI program example example http://stoneskin.dns2go.com:888/db/ http://stoneskin.dns2go.com:888/db/ http://stoneskin.dns2go.com:888/db/ http://stoneskin.dns2go.com:888/p/login. html http://stoneskin.dns2go.com:888/p/login. html
15
More Refence for detail infromation: please read w32::ODBC documintation http://www.roth.net/perl/odbc/docs/ for detail infromation: please read w32::ODBC documintation http://www.roth.net/perl/odbc/docs/ http://www.roth.net/perl/odbc/docs/ some samples and source codes http://multiweb.lib.calpoly.edu/odbc/ some samples and source codes http://multiweb.lib.calpoly.edu/odbc/ http://multiweb.lib.calpoly.edu/odbc/ Thanks. Thanks.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.