Gossamer Forum
Home : General : Perl Programming :

Perl/ Database

Quote Reply
Perl/ Database
Perl / Database
Can you please tell me how to write a command line tool to read the name of a table and the name of a column in that table from the user. Then to print out the values in that column to the user. Note that $myvar = <STDIN>; reads a single line of text from the user.What built in classes should be used and what would they do?. it doesnt matter if all the perl syntax is not remembered, as i just need a general idea of how to do it.
Thanx
Quote Reply
Re: [Dav] Perl/ Database In reply to
Quote:
an you please tell me how to write a command line tool to read the name of a table and the name of a column in that table from the user.

Not really something that you can give sample code(s) for Tongue

May be worth looking here: http://www.danchan.com/.../16/mysql/mysql3.htm

This gives you examples on how to use it, along with details on what each part does.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Perl/ Database In reply to
OK, so i tried to out some code down n came up with this... #!/usr/bin/perl

use DBI;
print "Enter a name in the TABLE\n";
$dbtable = <STDIN>;
chomp ($dbtable);
print "Enter a name in the COLUMN\n";
$dbcolumn = <STDIN>;
chomp ($dbcolumn);
sub getValues
{
$db = DBI->connect( "DBI:CSV:f_dir=DATA" );
if ( !$db )
{
die "<h1>Cannot Connect to Database</h1>";
}

$stat = $db->prepare(
"SELECT $dbcolumn FROM $dbtable ORDER BY letter ASC" );
$stat->execute();
while( my @row = $stat->fetchrow_array )
{
foreach $row(@row) {
print $row;
}
}
$db->disconnect();
@letters;
}

I know the syntax isnt totally correct but what else is wrong...?

Thanks