1 / 15

How to using MS Access database in Perl/CGI Web Programming

How to using MS Access database in Perl/CGI Web Programming. Wei Sun. Introduction. ODBC stands for: O pen D ata B ase C onnectivity The ODBC standard was designed to work on any platform and has been ported to win32, unix, macintosh, os/2 and others. Introduction. X/Open

kenaz
Download Presentation

How to using MS Access database in Perl/CGI Web Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to using MS Access database in Perl/CGI Web Programming Wei Sun

  2. Introduction • ODBC stands for: OpenDataBaseConnectivity • The ODBC standard was designed to work on any platform and has been ported to win32, unix, macintosh, os/2 and others.

  3. Introduction • X/Open • SQL Access Group • ANSI • ISO • Microsoft • Digital • Sybase • IBM • Novell • Oracle • Lotus • and others. ODBC was designed by:

  4. Program calls an ODBC Module. ODBC Module call the ODBC Perl Program Win32:ODBC Introduction ODBC Manager determines what to do. ODBC Manager ODBC Driver performs actual processing. ODBC Driver Database Access file The database file is opened by the driver and data is manipulated.

  5. Install win32::odbc module • step one:(perl 5.XXX need) Download win32-ODBC.zip from http://www.activestate.com/PPMPackages/zips/5xx-builds-only/Win32-ODBC.zipReadme Win32-ODBC.ppd Win32-ODBC.tar.gz • step two: In dos windows, in the fold in which you unziped win32-odbc:ppm install Win32-ODBC.ppdorppm 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 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 a) open Start->Setting->Contrl Panel->data source(ODBC), select MS Access Database in User DSN . • step two Data Source Name Database InformationUseridPasswordConnection 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".

  8. Build a Database and Configure in ODBC • 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 #!perl use Win32::ODBC;

  10. Test your database in Perl/CGI program • 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.</br>"; print "Error:".win32::ODBC::Error()."<br>\n"; exit; } else{ print "connected to database (connected number", $db->Connection(), ")<br>"; }

  11. Test your database in Perl/CGI program • C)show the table list in the database @tables = $db->TableList; print @tables; • 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 #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 $db->Close();

  14. Test your database in Perl/CGI program • example • http://stoneskin.dns2go.com:888/db/ • http://stoneskin.dns2go.com:888/p/login.html

  15. More Refence • for detail infromation: please read w32::ODBC documintationhttp://www.roth.net/perl/odbc/docs/ • some samples and source codeshttp://multiweb.lib.calpoly.edu/odbc/ Thanks.

More Related