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

Similar documents
WEB DB PRESS Vol.1 65

hands_on_4.PDF

スライド 0

tkk0408nari

PowerPoint Presentation

LAPP/LAMP (SQL + cgi)


ストラドプロシージャの呼び出し方

2003年度 情報処理概論

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

2009 Web B012-1

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

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

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

22 (266) / Web PF-Web Web Web Web / Web Web PF-Web Web Web Web CGI Web Web 1 Web PF-Web Web Perl C CGI A Pipe/Filter Architecture Based Software Gener

_IMv2.key

1 SQL Server SQL Oracle SQL SQL* Plus PL/SQL 2 SQL Server SQL Server SQL Oracle SQL SQL*Plus SQL Server GUI 1-1 osql 1-1 Transact- SQL SELECTFROM 058

橡t15-shibuya.kashiwa.ppt

6 (1) app.html.eex 28 lib/nano_planner_web/templates/layout/app.html.eex 27 <footer> Oiax Inc <%= this_year() %> Oiax Inc. 29 </footer>

リスト 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=

TopLink å SampleClient.java... 5 Ò readallsample() querysample() cachesample() Ç..

IIJ Technical WEEK Cloudbusting Machine(CBM)

̤Äê

com.ibm.etools.egl.jsfsearch.tutorial.doc.ps

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


Microsoft Word - PHP_SQLServer2012


mod_perl_jobworker

Sokushu2_perl

soturon2013

XML Consortium & XML Consortium 1 XML Consortium XML Consortium 2

橡実践Oracle Objects for OLE

ブログ制作教材


,, create table drop table alter table

CodeIgniter Con 2011, Tokyo Japan, February

(CC Attribution) Lisp 2.1 (Gauche )

01-Perl-oo_Kansai.pm#8.ppt

Gray [6] cross tabulation CUBE, ROLL UP Johnson [7] pivoting SQL 3. SuperSQL SuperSQL SuperSQL SQL [1] [2] SQL SELECT GENERATE <media> <TFE> GENER- AT


JavaScript の使い方

TopLink È... 3 TopLink...5 TopLink åø... 6 TopLink å Workbench O/R ~... 8 Workbench À ~... 8 Foundation Library å... 8 TopL

RubyKaigi2009 COBOL

Microsoft Word - tutorial3-dbreverse.docx

10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false

Microsoft Word - Android_SQLite講座_画面800×1280

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

Oracle JDeveloper 10g ADF Creation Date: Jul 07, 2004 Last Update: Jul 08, 2004 Version 1.0

Microsoft PowerPoint pptx

日本オラクル株式会社

ビジネスサーバ設定マニュアル_Standard応用編

<td width=99%><input type="file" size="80" name="file"></td> <td width=1% nowrap align=right valign=top> 削除キー : </td> <td width=99%><input type="passw

CAC

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

0.2 Button TextBox: menu tab 2

Webデザイン論

Wiki Wiki Wiki...

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>\

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

HP OpenSource ブループリント


橡j_Oracle_whitepaper.PDF

結合演算 ( 復習 ) データベース論 (9) R 社員番号 氏名麻生太郎安部晋三与謝野馨森喜朗 部門経理課営業課総務課営業課 S 部門経理課営業課総務課 電話 問合せ言語と SQL(2) R S 社員番号

Microsoft Word - J doc

CMP演習

FileMaker ODBC and JDBC Guide

untitled

2

FileMaker 16 ODBC と JDBC ガイド

untitled

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

mySQLの利用

untitled

A/B (2010/10/08) Ver kurino/2010/soft/soft.html A/B

オンラインテスト

MySQL5.0データベース ログファイルおよびステータスの収集

"CAS を利用した Single Sign On 環境の構築"

演習室の PC のハードディスクには演習で作成したデータは保管できません 各 PC の ネットワーク接続 ショートカットからメディア情報センターのサーバーにアクセスしてください (Z ドライブとして使用できます ) 講義で使うフォルダ 2/23

Word 2000 Standard

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

AuthorManual_JSTP.ppt

Webデザイン論

untitled

// JDBC // CallableStatement cs = null; try { cs = conn.preparecall("{call DUMMY_PROC(?,?)}"); cs.setstring(1, "This is a test"); cs.registeroutparame

PowerPoint プレゼンテーション

情報システム設計論II ユーザインタフェース(1)

Oracle Database Connect 2017 JPOUG

Oracle Lite Tutorial

n n n ( ) n Oracle 16 PostgreSQL 3 MySQL

052-XML04/fiÁ1-part3-’ÓŠ¹


Warehouse Builderにおける予測分析の使用

CPANモジュールについて

スライド 1

SQLite データベース IS04 組み込み 1


Łñ“’‘‚2004

プリント


Transcription:

WEB DB PRESS Vol.1 79

3 Powered by mod_perl, Apache & MySQL use Item; my $item = Item->new( id => 1, name => ' ', price => 1200, http://www.postgresql.org/http://www.jp.postgresql.org/ 80 WEB DB PRESS Vol.1

photo => 'http://hostname/image/image01.gif', feature => ' ', size => '20x30x10' print $item->name; print $item->photo; print $item->price, " n"; # 1,200 $item->price(960 # 2! print $item->price, " n"; # 960 package Item; sub new my $class = shift; my %args = @_; my $self = bless name => undef, price => 0, photo => undef, feature => undef, size => undef,, $class; $self->_initialize(%args sub _initialize my %args = @_; foreach my $name (keys %args) if ($name eq 'id') $self->id($args$name) elsif ($name eq 'name') $self->name($args$name) elsif ($name eq 'price') $self->price($args$name) elsif ($name eq 'photo') $self->photo($args$name) elsif ($name eq 'feature') $self->feature($args$name) elsif ($name eq 'size') $self->size($args$name) sub id if (@_) $self->id = shift $self->id; sub name if (@_) $self->name = shift $self->name; sub price if (@_) $self->price = shift $self->price; sub photo if (@_) $self->photo = shift $self->photo; sub feature if (@_) $self->feature = shift $self->feature; sub size if (@_) $self->size = shift $self->size; 1; END WEB DB PRESS Vol.1 81

3 Powered by mod_perl, Apache & MySQL w package Catalog; use DBI; use Item; sub new my $class = shift; my $item_id = shift; my $self = bless handle => undef, state => undef,, $class; $self->_initialize($item_id return Item->new( id => $record->[0], name => $record->[1], price => $record->[2], photo => $record->[3], q feature => $record->[4], size => $record->[5], sub close $self->state->finish if $self->state; $self->handle->disconnect if $self->handle; sub _initialize my $item_id = shift; my $handle = $self->handle; eval if (defined $item_id) $self->state( $handle->prepare(q SELECT id, name, price, photo, feature, size FROM catalog WHERE id =? ) $self->state->execute($item_id else $self->state( $handle->prepare(q SELECT id, name, price, photo, feature, size FROM catalog ) $self->state->execute; ; if ($@) die $@ sub get_item my $state = $self->state; return undef unless my $record = $state->fetchrow_arrayref; sub handle unless ($self->handle) eval $self->handle = DBI->connect(] 'dbi:mysql:webapp', 'user', 'password', RaiseError => 1 ) or die; ; if ($@) die "connect: $@" $self->handle; sub state if (@_) $self->state = shift $self->state; sub DESTROY $self->close; 1; END w 82 WEB DB PRESS Vol.1

q use Catalog; my $catalog = Catalog->new; while (my $item = $catalog->get_item) push @items, $item; $catalog->close; #!/usr/bin/perl use Catalog; my $catalog = Catalog->new; while (my $item = $catalog->get_item) printf "%s t%s n", $item->name, $item->price; END q t w e r > mysqladmin -u user -p create webapp Enter password: xxxxxxxxxx Database "webapp" created. > mysql -u user -p webapp Enter password: xxxxxxxxxx mysql> mysql> CREATE TABLE catalog -> (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -> name VARCHAR(100), price INT, -> photo VARCHAR(100), feature VARCHAR(255), -> size VARCHAR(100) -> Query OK, 0 rows affected (0.12 sec) WEB DB PRESS Vol.1 83

3 Powered by mod_perl, Apache & MySQL package Cart; use Apache::Session::DB_File; my $target = shift; splice @$self->session->item, $target, 1; sub new my $class = shift; my $session_id = shift; my $self = bless session =>, $class; $self->_initialize($session_id sub _initialize my $session_id = shift; sub item $self->session->item = [] unless exists $self->session->item; return (@$self->session->item sub session if (@_) $self->session = shift $self->session; r t eval tie %$self->session, 'Apache::Session::DB_File', $session_id, FileName => '/usr/home/oyama/var/sessions.db', LockDirectory => '/usr/home/oyama/var/lock/sessions', ; ; if ($@) die create_session: $@ sub add_item my @item = @_; push @$self->session->item, @item; sub delete_item q w e sub id $self->session->_session_id; sub close $self->session = ; sub DESTROY $self->session->last_access = time; untie %$self->session; 1; END y u i d f d f d f d f 84 WEB DB PRESS Vol.1

u i y $register->order( Address => ' 35F', Name => '', Phone => '03-1234-5678', my $register = Register->new($cart > mysql -u user -p webapp Enter password: xxxxxxxxxx mysql> mysql> CREATE TABLE order_info -> (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -> session_id CHAR(32), item_id INT, -> item_name VARCHAR(100), item_price INT, -> address VARCHAR(255), name VARCHAR(100), -> phone VARCHAR(50) -> Query OK, 0 rows affected (0.12 sec) <HTML> <BODY> <TMPL_LOOP name=item_list> <TMPL_VAR name=name><br> <TMPL_VAR name=price><br> <IMG src="<tmpl_var name=photo>"><br> <TMPL_VAR name=feature><br> <TMPL_VAR name=size><br> <A href="<tmpl_var name=add_cart_uri>">add cart</a><br> <HR> </TMPL_LOOP> <A href="<tmpl_var name=cart_uri>">show cart infomation</a><br> </BODY> </HTML> WEB DB PRESS Vol.1 85

3 Powered by mod_perl, Apache & MySQL package Register; use DBI; sub new my $class = shift; my $cart = shift; my $self = bless handle => undef, state => undef, items => [],, $class; $self->cart($cart sub order my %customer = @_; $self->_check_customer_info(%customer) or die "order: Wrang customer infomation"; my $handle = DBI->connect( 'dbi:mysql:webapp', 'root', 'test', RaiseError => 1, # AutoCommit => 0, my $state = $handle->prepare(q INSERT INTO order_info (session_id, item_id, item_name, item_price, address, name, phone) VALUES (?,?,?,?,?,?,?) eval my $session_id = $self->cart->id; foreach my $item ($self->cart->item) $state->execute( $session_id, $item->id, $item->name, $item->price, $customeraddress, $customername, $customerphone, ; if ($@) die "order: $@" else # $handle->commit; $handle->disconnect; sub _check_customer_info my %customer = @_; return undef unless defined $customeraddress; return undef unless defined $customername; return undef unless defined $customerphone; return sub cart if (@_) $self->cart = shift $self->cart; 1; END 86 WEB DB PRESS Vol.1

q w e q w y e #!/usr/bin/perl use CGI; use HTML::Template; use Catalog; my $query = CGI->new; my $html = HTML::Template->new(filename => 'catalog.html' q my $catalog = Catalog->new; my $item_list = []; while (my $item = $catalog->get_item) push @$item_list, NAME => $item->name, PRICE => $item->price, PHOTO => $item->photo, w FEATURE => $item->feature, SIZE => $item->size, ADD_CART_URI => 'cart.cgi?mode=add'. '&item='. $item->id ; $html->param(item_list => $item_list $html->param(cart_uri => 'cart.cgi' print $query->header; print $html->output; e WEB DB PRESS Vol.1 87

3 Powered by mod_perl, Apache & MySQL r t #!/usr/bin/perl use CGI; use HTML::Template; use Catalog; use Cart; my $query = CGI->new; my $cart = Cart->new($query->cookie(-name => 'session_id') my $mode = $query->param('mode' if ($mode eq 'add') my $item = load_item($query->param('item') $cart->add_item($item elsif ($mode eq 'delete') $cart->delete_item($query->param('index') q w e my $html = HTML::Template->new(filename => 'cart.html' my $item_list = []; my $index = 0; foreach my $item ($cart->item) push @$item_list, ID => $item->id, NAME => $item->name, PRICE => $item->price, DELETE_CART_URI => 'cart.cgi?mode=delete'. '&index='. $index++, ; $html->param(item_list => $item_list $html->param(catalog_uri => 'catalog.cgi' $html->param(register_uri => 'register.cgi' my $state_cookie = $query->cookie( -name => 'session_id', -value => $cart->id, -path => '/cgi-bin/', print $query->header(-cookie => $state_cookie print $html->output; r t sub load_item my $item_id = shift; my $catalog = Catalog->new($item_id return $catalog->get_item; y 88 WEB DB PRESS Vol.1

e r <HTML> <BODY> <TMPL_LOOP name=item_list> <TMPL_VAR name=id> <TMPL_VAR name=name> <TMPL_VAR name=price> <A href="<tmpl_var name=delete_cart_uri>">delete this item</a> <HR> </TMPL_LOOP> <A href="<tmpl_var name=catalog_uri>">catalog</a> <A href="<tmpl_var name=register_uri>">register</a> </BODY> </HTML> #!/usr/bin/perl use CGI; use HTML::Template; use Register; use Cart; use Item; my $query = CGI->new; my $cart = Cart->new($query->cookie(-name => 'session_id') if ($query->param('address') and $query->param('name') and $query->param('phone')) store_order_information($query, $cart q $cart->close; show_finish($query else show_input_form($query, $cart sub store_order_information my $query = shift; my $cart = shift; my $register = Register->new($cart $register->order( Address => $query->param('address'), Name => $query->param('name'), Phone => $query->param('phone'), sub show_finish my $query = shift; my $html = HTML::Template->new( w filename => 'finish.html', associate => $query $html->param(catalog_uri => 'catalog.cgi' my $expired_cookie = $query->cookie( -name => 'session_id', -value => '', -path => '/cgi-bin/', -expires => 0, print $query->header(-cookie => $expired_cookie print $html->output; sub show_input_form my $query = shift; my $cart = shift; my $html = HTML::Template->new( filename => 'register.html', e associate => $query my $item_list = []; my $index = 0; foreach my $item ($cart->item) push @$item_list, NAME => $item->name, PRICE => $item->price, DELETE_CART_URI => 'cart.cgi?mode=delete'. '&index='. $index++, ; $html->param(item_list => $item_list $html->param(catalog_uri => 'catalog.cgi' $html->param(marking_address => $query->param('address')? '' : '*' $html->param(marking_name => $query->param('name')? '' : '*' r $html->param(marking_phone => $query->param('phone')? '' : '*' print $query->header; print $html->output; WEB DB PRESS Vol.1 89

3 Powered by mod_perl, Apache & MySQL q w <HTML> <BODY> <TMPL_LOOP name=item_list> <TMPL_VAR name=name> <TMPL_VAR name=price> <A href="<tmpl_var name=delete_cart_uri>">delete this item</a> <HR> </TMPL_LOOP> <A href="<tmpl_var name=catalog_uri>">catalog</a> <FORM method="get" action="register.cgi"> Address: <INPUT type="text" name="address" value="<tmpl_var name=address>"><blink><font color="#ff0000"><tmpl_var name=marking_address></font></blink><br> Name: <INPUT type="text" name="name" value="<tmpl_var name=name>"><blink><font color="#ff0000"><tmpl_var name=marking_name></font></blink><br> Phone: <INPUT type="text" name="phone" value="<tmpl_var name=phone>"><blink><font color="#ff0000"><tmpl_var name=marking_phone></font></blink><br> <INPUT type="submit" value="submit"> </FORM> </BODY> </HTML> <HTML> <BODY> Thank you.<br> <TMPL_VAR name=address><br> <TMPL_VAR name=name><br> <TMPL_VAR name=phone><br> <A href="<tmpl_var name=catalog_uri>">catalog</a> </BODY> </HTML> http://httpd.apache.org/ http://www.apache.or.jp/ 90 WEB DB PRESS Vol.1

> ab -c 10 -t 100 http://localhost/cgi-bin/catalog.cgi http://www.macromedia.com/ http:// valueclick.com/ http://www. mp3.com/ http://perl.apache.org/guide/intro.html WEB DB PRESS Vol.1 91