Trevor Tregoweth wrote:
HI All

i was wondering if someone could help me, this is probably a simple task, but for 
someone thats not done any before it seems impossible
I have a mysql database, with data in it, and i would like to be able to produce that 
data on a web page, so would appreciate some examples, i don't mind if its simple, 
just want to be able to view it via a web page

This is an example of a perl script that connects to a database of Journals on my laptop. The MySQL database is called 'Journal'
Note this is not meant to be secure its just a test I had around.


----- perl script --------------

#!/usr/bin/perl

use strict;
use warnings;
use DBI;

my $user = 'root';
my $password = 'your_mysql_root_password';
my @row;

my $date = `date '+%a %b %d, %Y'`; chomp $date;

# Connect to the Database
my $dbh = DBI->connect('dbi:mysql:Journal', $user, $password,
    { RaiseError => 1, AutoCommit => 0 });

my $query = $dbh->prepare("SELECT * FROM journal");
$query->execute;

# Print the HTML header - note the two blank lines \r\n\r\n
print qq{Content-type: text/html\r\n\r\n
<html>
<head><title>ASF KID Test</title></head>
<body><h1>Test Database Access</h1>
};

# Print the data preformatted.
print "Todays date: $date <p>";
print"<pre>";
while ( @row = $query->fetchrow_array ) {
    print "@row<br>";
}
print"</pre>";

# Print the HTML end.
print qq{
</body>
</html>
};

$query->finish;
$dbh->disconnect;

---------- end of Perl script --------------

Here is the output as a HTML page
Its the Journal_id, volume, part, the issue_month, issue_year.

Test Database Connectivity

Todays date: Thu Aug 05, 2004

2 133 3 4 December 2000
3 134 1 2 June 2001
4 134 3 4 December 2001
5 135 1 2 July 2002
6 135 3 4 April 2003
7 136 1 4 December 2003

------- end HTML ------


Here is the Journal database table that was queried: Sorry it wrapped badly so I cut bits out but you get the idea.

+-------------+-----------------+
| Field | Type | Null | Key | Default | Extra
+-------------+---------------------+
| journal_id | int(10) unsigned
| volume
| part


| issue_month | enum('January','February','March','April','May','June','July','August','September','October','November','December')
| issue_year | year(4)


+-------------+----------------+


Hope this helps.

Mike
--
Mike Lake
Caver, Linux enthusiast and interested in anything technical.

--
UTS CRICOS Provider Code:  00099F
DISCLAIMER: This email message and any accompanying attachments may contain
confidential information.  If you are not the intended recipient, do not
read, use, disseminate, distribute or copy this message or attachments.  If
you have received this message in error, please notify the sender immediately
and delete this message. Any views expressed in this message are those of the
individual sender, except where the sender expressly, and with authority,
states them to be the views the University of Technology Sydney. Before
opening any attachments, please check them for viruses and defects.
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to