WEB DB PRESS Vol.1 65

Similar documents
3 Powered by mod_perl, Apache & MySQL use Item; my $item = Item->new( id => 1, name => ' ', price => 1200,

hands_on_4.PDF

ii II Web Web HTML CSS PHP MySQL Web Web CSS JavaScript Web SQL Web

untitled

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

リスト 1 1 <HTML> <HEAD> 3 <META http-equiv="content-type" content="text/html; charset=euc-jp"> 4 <TITLE> 住所の検索 </TITLE> 5 </HEAD> 6 <BODY> <FORM method=

インターネットマガジン2003年3月号―INTERNET magazine No.98

橡環境設定.PDF


CAS Yale Open Source software Authentication Authorization (nu-cas) Backend Database Authentication Authorization Powered by A

オンラインテスト


…l…b…g…‘†[…N…v…“…O…›…~…fi…OfiÁŸ_

2 Java 35 Java Java HTML/CSS/JavaScript Java Java JSP MySQL Java 9:00 17:30 12:00 13: 項目 日数 時間 習得目標スキル Java 2 15 Web Java Java J

2009 Web B012-1

# mv httpd tar.gz /usr/local/src /usr/local/src # tar zxvf httpd tar.gz make #./configure # make # make install Apache # /usr/local/apac

dvi

実験 5 CGI プログラミング 1 目的 動的にWebページを作成する手法の一つであるCGIについてプログラミングを通じて基本的な仕組みを学ぶ 2 実験 実験 1 Webサーバの設定確認と起動 (1)/etc/httpd/conf にある httpd.conf ファイルの cgi-bin に関する

PostgreSQLによる データベースサーバ構築技法

Web apache

unix.dvi

IIJ Technical WEEK Cloudbusting Machine(CBM)

¥Í¥Ã¥È¥ï¡¼¥¯¥×¥í¥°¥é¥ß¥ó¥°ÆÃÏÀ

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

PostgreSQL

UNIX

54 5 PHP Web hellow.php 1:<?php 2: echo "Hellow, PHP!Y=n"; 3:?> echo PHP C 2: printf("hellow, PHP!Y=n"); PHP (php) $ php hellow.php Hellow, PHP! 5.1.2

RT300/140/105シリーズ 取扱説明書

RTX830 取扱説明書

Abstract Journal of Agricultural Science 2


IIJ Technical WEEK アプリ開発を楽にするRuby PaaS「MOGOK」について

5-5_arai_JPNICSecSemi_XssCsrf_CM_ PDF

1 ex01.sql ex01.sql ; user_id from (select user_id ;) user_id * select select (3+4)*7, SIN(PI()/2) ; (1) select < > from < > ; :, * user_id user_name

e164.arpa DNSSEC Version JPRS JPRS e164.arpa DNSSEC DNSSEC DNS DNSSEC (DNSSEC ) DNSSEC DNSSEC DNS ( ) % # (root)

help gem gem gem my help

New version (2.15.1) of Specview is now available Dismiss Windows Specview.bat set spv= Specview set jhome= JAVA (C:\Program Files\Java\jre<version>\

etrust Access Control etrust Access Control UNIX(Linux, Windows) 2

1,.,,,., RDBM, SQL. OSS,, SQL,,.


~~~~~~~~~~~~~~~~~~ wait Call CPU time 1, latch: library cache 7, latch: library cache lock 4, job scheduler co

RT300i/RT140x/RT105i 取扱説明書

Cleaner XL 1.5 クイックインストールガイド

_IMv2.key

Northern Lights Server

programmingII2019-v01

syspro-0405.ppt

Plan of Talk CAS CAS 2 CAS Single Sign On CAS CAS 2 CAS Aug. 19, 2005 NII p. 2/32

Introduction Purpose This training course describes the configuration and session features of the High-performance Embedded Workshop (HEW), a key tool

TeraTerm Pro V.2.32の利用法

付録B

Copyright 2006 Mitsui Bussan Secure Directions, Inc. All Rights Reserved. 3 Copyright 2006 Mitsui Bussan Secure Directions, Inc. All Rights Reserved.

HA8000シリーズ ユーザーズガイド ~BIOS編~ HA8000/RS110/TS10 2013年6月~モデル

owners.book

BC4J...4 BC4J Association JSP BC4J JSP OC4J

TM-T88VI 詳細取扱説明書

設定例集_Rev.8.03, Rev.9.00, Rev.10.01対応

Web SOAP Internet Web REST SOAP REST 3 REST SOAP 4

csj-report.pdf

橡Ⅳインストールマニュアル.PDF

,, create table drop table alter table

Asterisk PBX 不正利用防止

Transcription:

http://www.fastcgi.com/ http://perl.apache.org/ 64 WEB DB PRESS Vol.1

WEB DB PRESS Vol.1 65

Powered by mod_perl, Apache & MySQL my $input; my %form; read STDIN, $input, $ENV{'CONTENT_LENGTH'}; foreach my $key_and_value (split /&/, $input) { my ($key, $value) = split /=/,$key_and_value; $form{$key} = $value; } use CGI; my $query = CGI->new; http://www.zope.org/ http://www.zope.ne.jp/ http://www.masonhq.com/ http://www.perldoc.com/perl5.6/lib/cgi.html http://member.nifty.ne.jp/hippo2000/perltips/cgi.htm 66 WEB DB PRESS Vol.1

$query->param('name'); <HTML> <BODY> <FORM method="post" action="sample.cgi"> <INPUT type="text" name="comment"> <SELECT name="language"> <OPTION value="perl">perl <OPTION value="python">python <OPTION value="ruby">ruby </SELECT> </FORM> </BODY> </HTML> http://hostname/sample.cgi?comment=cool print $query->param('comment'); # it's "cool" #!/usr/bin/perl use CGI; my $query = CGI->new; print $query->param('comment'); print $query->param('language'); END $obj = CGI->new; $obj->param; $obj->param(name); my @name_list = $obj->param; my $value = $obj->param($name); $obj->header; $obj->header( $obj->header(content_type); -type => 'image/gif', $obj->header(list); -expires => '+1m', ); $obj->redirect(url); $obj->cookie(list) my $cookie = $obj->cookie( -name => 'session_id', -value => 'id_strings', -expires => '+1d', ); print $obj->header(-cookie => $cookie); WEB DB PRESS Vol.1 67

Powered by mod_perl, Apache & MySQL $handle = DBI->connect($data_ my $handle = DBI->connect($data_source, source, $username, $passwd); $username, $passwd, { RaiseError => 1, AutoCommit => 0 }); $state = $handle->prepare(sql); $state->execute; $state->execute(list); $state = $handle->do(sql); $record = $state->fetchrow_arrayref; $handle->commit; my $handle = DBI->connect($data_source, $username, $passwd, { RaiseError => 1, AutoCommit => 0, $handle->rollback; }); eval { $handle->do(q{ DELETE FROM table WHERE status = 'DONE' }); }; if ($@) { $handle->rollback; # clean up code } else { $handle->commit; } $handle->disconnect; http://www.symbolstone.org/technology/perl/dbi/ http://member.nifty.ne.jp/hippo2000/perltips/dbimemo.htm 68 WEB DB PRESS Vol.1

my $state = $handle->prepare(q{ SELECT column1, column2 FROM table }); use DBI; my $handle = DBI->connect($data_source, $username, $password); dbi:drivername:database_name dbi:drivername:database_name@hostname:port dbi:drivername:database_name;host=hostname;port=port my $state = $handle->prepare(q{ SELECT name, email, age FROM table WHERE age ==? }); $state->execute(); $state->execute($age); while (my $record = $state->fetchrow_arrayref) { print 'Name: ', $record->[0]; print 'Email: ', $record->[1]; print 'Age: ', $record->[2]; } WEB DB PRESS Vol.1 69

Powered by mod_perl, Apache & MySQL $handle->disconnect(); #!/usr/bin/perl use DBI; my $handle = DBI->connect( 'dbi:mysql:customer', 'user', 'password' ); my $state = $handle->prepare(q{ INSERT INTO language (name, version, url) VALUES (?,?,?) }); while (my $line = <>) { chomp $line; $state->execute(split /\t/, $line); } $handle->disconnect; END http://www.mysql.com/ http://www.softagency.co.jp/ http://www.mysql.gr.jp/ http://www.perldoc.com/cpan/apache/session.html http://member.nifty.ne.jp/hippo2000/perltips/apache/session.htm 70 WEB DB PRESS Vol.1

#!/usr/bin/perl use DBI; my $handle = DBI->connect( 'dbi:mysql:customer', 'user', 'password' ); my $state = $handle->prepare(q{ SELECT name, version, url FROM language }); $state->execute; while (my $record = $state->fetchrow_arrayref) { printf "%s, %s, %s\n", $record->[0], # name $record->[1], # version $record->[]; # url } $handle->disconnect; END use Apache::Session::DB_File; my %session; tie %session, 'Apache::Session::DB_File', $session_id, { FileName => '/var/sessions.db', LockDirectory => '/var/lock/sessions', }; tie %hash, CLASS_NAME; tie %hash, CLASS_NAME, $session_id, use Apache::Session::MySQL; tie %session, 'Apache::Session::MySQL', \%option; $session_id, { DataSource => 'dbi:mysql:sessions', }; $hash{_session_id}; tied(%hash)->delete; untie %hash; WEB DB PRESS Vol.1 71

Powered by mod_perl, Apache & MySQL $session{name} = 'value'; print $session{name}; print $session{_session_id}; untie %session; $session{last_access} = time; untie %session; http://sourceforge.net/cvs/?group_id=1075 http://member.nifty.ne.jp/hippo2000/perltips/html/template.htm http://www.php.net/http://www.php.gr.jp/ 72 WEB DB PRESS Vol.1

#!/usr/bin/perl use Apache::Session::DB_File; use CGI; my $query = CGI->new; my $session_id = $query->cookie(-name => 'session_id'); my %session tie %session, 'Apache::Session::DB_File', $session_id, { FileName => '/var/sessions.db', LockDirectory => '/var/lock/sessions', }; ++$session{access}; my $html = << HTML_BODY ; <HTML> <BODY> Your Access: $session{access} </BODY> </HTML> HTML_BODY my $state_cookie = $query->cookie( -name => 'session_id', -value => $session{_session_id}, ); print $query->header(-cookie => $state_cookie); print $html; END <HTML> <BODY> <TMPL_VAR name=list_name> <TMPL_LOOP name=language> Name: <TMPL_VAR name=name> URL: <TMPL_VAR name=url> <HR> </TMPL_LOOP> </BODY> </HTML> $html->param('language' => [ { NAME => 'Perl', URL => 'http://www.perl.com/', }, { NAME => 'Python', URL => 'http://www.python.org/', }, { NAME => 'Ruby', URL => 'http://www.ruby-lang.org/', }, ]); use HTML::Template; my $html = HTML::Template->new( filename => '/path/to/template.html' ); WEB DB PRESS Vol.1 7

Powered by mod_perl, Apache & MySQL $html->param('list_name' => ''); print $html->output; <HTML> <BODY> Name: Perl URL: http://www.perl.com/ <HR> Name: Python URL: http://www.python.org/ <HR> Name: Ruby URL: http://www.ruby-lang.org/ <HR> </TMPL_LOOP> </BODY> </HTML> #!/usr/bin/perl use HTML::Template; my $directory = $ARGV[0] './'; my $html = HTML::Template->new( filename => 'directory.html' ); my $file_list = []; opendir DIR, $directory; while (my $filename = readdir DIR) { push @{$file_list}, { NAME => $filename, SIZE => -s $filename, }; } $html->param(filelist => $file_list); $html->param(path => $directory); print $html->output; END <HTML> <HEAD><TITLE><TMPL_VAR name=path></title></head> <BODY> <TABLE> <TR> <TH>Name</TH> <TH>Size</TH> </TR> <TMPL_LOOP name=filelist> <TR> <TD><A href="<tmpl_var name=name>"><tmpl_var name=name></a></td> <TD><TMPL_VAR name=size></td> </TR> </TMPL_LOOP> </TABLE> </BODY> </HTML> 74 WEB DB PRESS Vol.1

> ftp www.cpan.org User: anonymous 1 Anonymous login ok, send your complete e- mail address as password. Password: your@email.address ftp> cd /CPAN/modules/by-module/Apache ftp> ls mod_perl-*.tar.gz mod_perl-1.21.tar.gz mod_perl-1.22.tar.gz mod_perl-1.2.tar.gz mod_perl-1.24.tar.gz ftp> ftp> get mod_perl-1.24.tar.gz ftp> quit > cd /usr/local/src > gzip -cd mod_perl-1.24.tar.gz tar xvf - mod_perl-1.24/ mod_perl-1.24/t/ mod_perl-1.24/t/docs/... > cd mod_perl-1.24 > perl Makefile.PL Configure mod_perl with../apache_1..14/src? [y] y Shall I build httpd in../apache_1..14/src for you? [y] y... WEB DB PRESS Vol.1 75

Powered by mod_perl, Apache & MySQL > make # cd../apache_1..14/src # cp -p httpd /usr/local/apache/bin/ > make test > su - Password: xxxxxxxxx # make install > perl Makefile.PL APACI_ARGS="--enablemodule=rewrite,--disable-module=userdir" AllowOverride None Options None Order allow,deny Allow from all <Directory "/usr/local/apache/cgi-bin"> </Directory> <Directory "/usr/local/apache/cgi-bin"> SetHandler perl-script PerlHandler Apache::Registry AllowOverride None Options +ExecCGI Order allow,deny Allow from all PerlSendHeader Off </Directory> 76 WEB DB PRESS Vol.1

<Directory "/usr/local/apache/cgi-bin"> SetHandler perl-script PerlHandler Apache::Registry PerlModule Apache::DBI AllowOverride None Options +ExecCGI Order allow,deny Allow from all PerlSendHeader Off </Directory> <Directory "/usr/local/apache/cgi-bin"> SetHandler perl-script PerlHandler Apache::PerlRun AllowOverride None Options +ExecCGI Order allow,deny Allow from all PerlSendHeader Off </Directory> http://www.cpan.org/ http://www.cpan.org/modules/by-module/ Apache/mod_perl-1.24.tar.gz http://www.cpan.org/modules/by-module/dbi/dbi- 1.14.tar.gz http://www.cpan.org/modules/by-module/ Apache/Apache-Session-1.5.tar.gz http://www.cpan.org/modules/by-module/html/html- Template-2.0.tar.gz WEB DB PRESS Vol.1 77

Powered by mod_perl, Apache & MySQL > gzip -cd package.tar.gz tar xvf - > cd package/ > perl Makefile.PL > make > make test > perl Makefile.PL PREFIX=/path/to/install/directory > make > make test > make install > su - Password: xxxxxxxxxx # make install > perldoc ModuleName 78 WEB DB PRESS Vol.1