PHPを利用したデータベースアクセスについては データベースを利用したWebPageを作成 にあります。
# tar zxvf data-dumper-2.09.tar.gz # tar zxvf dbi-1.06.tar.gz # tar zxvf msql-mysql-modules-1.2014.tar.gz
展開したカレントディレクトリに
# cd Data-Dumper-2.09 # perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for Data::Dumper # make ... # make test ... t/dumper............ok t/overload..........ok All tests successful. Files=2, Tests=139, 8 secs ( 7.19 cusr 0.31 csys = 7.50 cpu) # make install ... #
# cd DBI-1.06 # perl Makefile.PL ... Checking if your kit is complete... Looks good Writing Makefile for DBI ... # make ... # make test ... t/basics............ok t/dbidrv............ok ... All tests successful. ... test.pl done # make install
# cd Msql-Mysql-modules-1.2014 # perl Makefile.PL ... 1) MySQL 2) mSQL (1 or 2) 3) Both MySQL and mSQL 4) mSQL1 and mSQL2 5) Everything (MySQL, mSQL1 and mSQL2) Enter your choice: [3] 1 ... Creating Mysql files .................... Checking if your kit is complete... Looks good Writing Makefile for DBD::mysql Writing Makefile for Msql-Mysql-modules # make ... # make test ... qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t t/00base............ok t/10dsnlist.........ok t/20createdrop......ok t/30insertfetch.....ok t/40bindparam.......ok t/40blobs...........ok ... t/dbdadmin..........ok All tests successful. Files=14, Tests=258, 81 secs (41.91 cusr 3.83 csys = 45.73 cpu) # make install
Perlスクリプトを作成し動作の確認を行います。
データベースを利用したWebPageを作成
で作成したtest_dbに接続し確認を行うことにします。
test_dbにあるmailの部分を表示するPerlスクリプトの例です。
% cat test.pl #!/usr/local/bin/perl require DBD::mysql; $dbh = DBI->connect("DBI:mysql:test_db","",""); $sth = $dbh->prepare("select mail from test_db"); $rv = $sth->execute; print"MySQL Perl DBD::mysql TEST\n"; while(@row = $sth->fetchrow_array) { print "$row[0]\n"; } $rc = $dbh->disconnect; exit;このスクリプトを実行した結果です。
% ./test.pl MySQL Perl DBD::mysql TEST dareka@hoge.foo.bar tonari@host.foo.bar %