How to using MS Access database in Perl/CGI Web Programming Wei Sun
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.
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.
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
Install win32::odbc module step one: (perl 5.XXX need) step one: (perl 5.XXX need) Download win32-ODBC.zip from only/Win32-ODBC.zip Readme Win32-ODBC.ppd Win32-ODBC.tar.gz only/Win32-ODBC.zip 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= (if you use new version perl)
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)
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.
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.
Test your database in Perl/CGI program A) load odbc module A) load odbc module#!perl use Win32::ODBC;
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(), ") "; }
Test your database in Perl/CGI program C)show the table list in the database C)show the table list in the = $db->TableList; 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 = $db->FieldNames(); }
Test your database in Perl/CGI program E)insert, update, delete records E)insert, update, delete records #insert $sqlinsert = “ INSERT INTO address VALUES ('Euler', 28, ' ') "; #updata $sqlupdate = “ UPDATE address SET age = age+10 "; #del $sqldelete = “ DELETE FROM address WHERE name='jimtyan' ";
Test your database in Perl/CGI program 3.6 close the database 3.6 close the database$db->Close();
Test your database in Perl/CGI program example example html html
More Refence for detail infromation: please read w32::ODBC documintation for detail infromation: please read w32::ODBC documintation some samples and source codes some samples and source codes Thanks. Thanks.