I *just* got my first web page filled with data from a MySQL table.
There was a connection through MySQL,  PERL, Apache and a browser.
It's still amazes me how a few lines of text on the screen
can put me in such a good mood :-)

Much thanks for all the advise and sample code.

Some random notes to other clueless newbies (like myself)
1) Ya gotta use CPAN to get the perl MySQL-DBI modules installed.
Period.
The machine I am developing on has no LAN connection so I screwed around
downloading the tars and burning them on CD so I could move them to the
laptop.
I could not work out how to install them into perl; a complete waste of
time!
After I rigged up a dialup (another adventure) I had the DBI stuff loaded in
minutes.
2) I had the most troubles with the connect string.
2a) The localhost name thing screwed me up bigtime.
2b) The database user and password items are another minefield.
They are not necessarily the same as your OS user and login name.
MySQL has it's own user and password control.
3) I has to comment the "use strict" out to get rid of the compile errors in
the Apache error log.
Still don't know why the "strict" thing is so picky.
Do you have to declare vars in perl under "strict" rules?
4) The Apache error log is your best friend in sorting why the stuff is not
working.

Mark Browne


----- Original Message -----
From: "Thomas Eibner" <thomas at stderr.net>
To: <tclug-list at mn-linux.org>
Sent: Thursday, November 08, 2001 10:02 PM
Subject: Re: Learning CGI Database Wizardry (Was Re: [TCLUG] PostgreSQL
Advocacy (was Re: <TROLL> (was ...)))


On Thu, Nov 08, 2001 at 09:02:11PM -0600, Dave Sherohman wrote:
> #!/usr/bin/perl -wT
>
> use strict;
> use DBI;
>
> my $dbh = DBI->connect("dbi:Pg:host=SERVERNAME;dbname=DBNAME",
>                        "DBUSER", "DBPASSWORD")
>         || die "Failed to connect: $!\n";

$! doesn't return the real error here. use $DBI::errstr, DBI->errstr or
whatever style you like to call it with. (You can test this with suplying
PrintError => 0 to the attributes of the connect call.

Your version will just write:
Died at $0 line __LINE__

> my $qry = $dbh->prepare("select * from some_table");
> $qry->execute;

I'm just being pedantic here..sorry ;)

I'd rather have newcomers to DBI use the common (almost standard) name
of $sth instead of $qry. (Just for mantainability and when another
programmer has to look at the code.) I realize it's getting a bit
off-topic now.

> while (my @row = $qry->fetchrow_array) {
>   print @row;
> }
>
> $dbh->do("delete from some_table");

--
  Thomas Eibner <http://thomas.eibner.dk/> DnsZone <http://dnszone.org/>
  mod_pointer <http://stderr.net/mod_pointer>

_______________________________________________
Twin Cities Linux Users Group Mailing List - Minneapolis/St. Paul, Minnesota
http://www.mn-linux.org
tclug-list at mn-linux.org
https://mailman.mn-linux.org/mailman/listinfo/tclug-list