List:General Discussion« Previous MessageNext Message »
From:Ronald Beck Date:May 17 1999 5:46pm
Subject:Newbie questions
View as plain text  
Hello all,
I'm new to mysql and databases in general.  I have a web application
which needs to track employee numbers and ethernet address as well as
some additional employee information.

I've created my database, made a couple of entries and even got my perl
script to access the information in some fashion.

What I'm looking for now is some good basic examples on how to interface
the DBI/DBD stuff thru perl.  I've attached my code below if anyone
wants to comment.  I'm looking for any and all recommendations at this
point.  If there's a FAQ, please point me to it.  A manual, let me know,
we have a MicroCenter across the street.  

The database is nothing fancy.  One table which contains ethernet
address, the mainframe controller it's assigned to, employee ID, site,
location, update date and update technician.  Queries will mainly be in
the form of retriving all information in a record, adding a record,
deleting a record or updating the ethernet address of a record.  Pretty
straightforward stuff at this time.

Again, any recommendations will be greatly accepted and flames retarded.


***************** Current perl test code **********************
use CGI;
use DBI;

print "Assigning variable names\n";
$address = 'localhost';
$username = 'yyyyy';
$password = 'xxxxxxx';

print "executing the DBI->install_driver step\n";

$drh=DBI->install_driver('mysql') || cgidie("Could not load mysql

# Connect to the database engine.  Do to funky things I don't understand
# with Mysql, we need to connect to a database, not just the engine.
# I hope the database 'mysql' is installed everywhere...

print "Connecting to mysql\n";
$dbh=$drh->connect("mysql:$address","$username","$password") ||
cgidie("Failed to connect to mysql server\n");

# Find out what databases are available.
print "Determining what databases are available\n";

$cursor=$dbh->prepare("show databases") || cgidie("show databases
failed: ".$cursor->errstr);
while (@databases = $cursor->fetchrow) { push @list, $databases[0]; }
while ($database = shift @list) { print "Database: $database\n"; }
undef @list;

$cursor=$dbh->prepare("use ticcdb") || cgidie("Couldn't use ticcdb:
while (@databases = $cursor->fetchrow) { push @list, $databases[0]; }
while ($database = shift @list) { print "USE: $database\n"; }
undef @list;

$cursor =$dbh->prepare("show tables") || cgidie("Couldn't show tables:
while (@databases = $cursor->fetchrow) { push @list, $databases[0]; }
while ($database = shift @list) { print "Show Tables: $database\n"; }
undef @list;

$cursor =$dbh->prepare("show columns from enetmap") || cgidie("Couldn't
show tables: ".$cursor->errstr);
while (@databases = $cursor->fetchrow) { push @list, $databases[0]; }
while ($database = shift @list) { print "Show Columns: $database\n"; }
undef @list;

enetaddr,ctrlr,empno,assettag,site,coord,lastupdate,updateby from
enetmap;") || cgidie("Couldn't show select: ".$cursor->errstr);
while (@row = $cursor->fetchrow)
 { push @line,$row[0]; }
foreach $rec (@line)
 { print "$rec\n"; }
sub cgidie {
  ($die_str) = @_;
  print <<EOF
  die $dir_str;
Newbie questionsRonald Beck17 May