File: dbi1.htm

package info (click to toggle)
libembperl-perl 2.5.0-17
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 7,632 kB
  • sloc: ansic: 21,387; perl: 14,497; javascript: 4,280; cpp: 467; xml: 49; makefile: 35; sh: 24
file content (50 lines) | stat: -rwxr-xr-x 1,074 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

<html>
<head>
<title>Embperl Examples - DBI access using Dynamic Tables</title>
</head>
<body background="../images/jazzbkgd.gif">

<h1>Embperl Examples - DBI access using Dynamic Tables</h1>
<hr><b>NOTE:</b><br>
You must set the database and table to something which exists on your system<br>
Maybe it's necessary to insert a PerlModule DBI into your srm.conf to get this working<br>

<hr>

[-

$DSN   = 'dbi:mysql:test' ;
$table = 'dbixrs1' ;

use DBI ;

# connect to database
 $dbh = DBI->connect($DSN) or die "Cannot connect to '$DSN'" ;

# prepare the sql select
 $sth = $dbh -> prepare ("SELECT * from $table")  or die "Cannot SELECT from '$table'" ;

# excute the query
 $sth -> execute  or die "Cannot execute SELECT from '$table'";

# get the fieldnames for the heading in $head
 $head = $sth -> {NAME} ;

# get the result in $dat
 $dat = $sth -> fetchall_arrayref ;

-]

<table border=1>
	<tr><th>[+ $head->[$col] +]</th></tr>
	<tr><td>[+ $dat -> [$row][$col] +]</td></tr>
</table>

<p><hr>

<small>HTML::Embperl (c) 1997-1998 G.Richter</small>


</body>
</html>