Hello all!
a friend send me a script that can make a query from a MySQL into a
HTML Page
it has an error something like this but I dont know what is wrong
the error code :
Can't find string terminator "EOUsage" anywhere before EOF at
returnatable.pl line 7.
this is the code I am using perl for windows :
#!/usr/bin/perl
use DBI;
#Get arguments from command line
($db,$table,$out_file,$user,$pass)= [at] ARGV;
#Check for invalid info
unless($db && $table) {
print <<EOUsage;
Usage: $0 <database> <table> <out file> <user> <pass>
\tUnless you specify out file, STDOUT will be used.
\t(Sending an out file of '-' will generate the same result)
\tUser and Pass are optional.
EOUsage
exit();
}
#No out file if '-'
undef $out_file if($out_file eq '-');
#Connect to the DBI using our db, user, and pass
my $dbr=DBI->connect("dbi:mysql:$db",$user,$pass,{
PrintError=>0
}) or die "Can't connect to database; $DBI::errstr\n";
#Get all the rows from our table
my $sth=$dbr->prepare("SELECT * FROM $table")
or die "Can't prepare SQL statement: $DBI::errstr\n";
#Execute our command to get the rows
$sth->execute or die "Can't execute: $DBI::errstr\n";
#Open out_file
if($out_file) {
#Don't open file until now to avoid overwritting
# in case of errors
open OUT,">$out_file" or die "Cannot open $out_file for
writting: $!\n";
}
#Header html data
$head=<<EOHead;
<html>
<head>
<title>Database Summary</title>
</head>
<body>
<h1>Data in $db:$table</h1>
<table border=1>
EOHead
out($head);
#Print a table row for each database row
my [at] row;
while( [at] row=$sth->fetchrow_array()) {
out("<tr><td>" . join("</td><td>", [at] row) . "</td></tr>\n");
}
#HTML tail info
$tail=<<EOTail;
</table>
</body>
</html>
EOTail
#Close out_file
if($out_file) {
close OUT;
}
#Disconnect from the database
$dbr->disconnect;
#Use this sub to make it easier when using file || STDOU
sub out {
my $data=shift;
if($out_file) {
print OUT $data;
} else {
print $data;
}
}
I hope someone could help me thanks!
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules [at] m .gmane.org
