Debian Codegraph @

eg/x/dbi1.htm

raw
1
2 <html>
3 <head>
4 <title>Embperl Examples - DBI access using Dynamic Tables</title>
5 </head>
6 <body background="../images/jazzbkgd.gif">
7
8 <h1>Embperl Examples - DBI access using Dynamic Tables</h1>
9 <hr><b>NOTE:</b><br>
10 You must set the database and table to something which exists on your system<br>
11 Maybe it's necessary to insert a PerlModule DBI into your srm.conf to get this working<br>
12
13 <hr>
14
15 [-
16
17 $DSN = 'dbi:mysql:test' ;
18 $table = 'dbixrs1' ;
19
20 use DBI ;
21
22 # connect to database
23 $dbh = DBI->connect($DSN) or die "Cannot connect to '$DSN'" ;
24
25 # prepare the sql select
26 $sth = $dbh -> prepare ("SELECT * from $table") or die "Cannot SELECT from '$table'" ;
27
28 # excute the query
29 $sth -> execute or die "Cannot execute SELECT from '$table'";
30
31 # get the fieldnames for the heading in $head
32 $head = $sth -> {NAME} ;
33
34 # get the result in $dat
35 $dat = $sth -> fetchall_arrayref ;
36
37 -]
38
39 <table border=1>
40 <tr><th>[+ $head->[$col] +]</th></tr>
41 <tr><td>[+ $dat -> [$row][$col] +]</td></tr>
42 </table>
43
44 <p><hr>
45
46 <small>HTML::Embperl (c) 1997-1998 G.Richter</small>
47
48
49 </body>
50 </html>