Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHOW COLUMNS FROM table name PERL-->MySQL 1

Status
Not open for further replies.

skosterow

Technical User
Feb 23, 2002
135
US
okay guys and gals - im trying to write a little script that will help me write other scripts ---->

(BTW Ill post the completed script here for others to use as well)

Here is the prob im facing:

1 im trying to access a MySQL database - using perl - mysqlpp. here is the code:

---------------------------------------
my $dsn = "DBI:mysqlPP:$FORM::DATABASE:$DB::SERVER";
my $dbh = DBI->connect($dsn, $DB::USER, $DB::pASS);
my $sth = $dbh->prepare(qq{ SHOW COLUMNS FROM $FORM::TABLE });
$sth->execute();
while (($DB::01, $DB::02, $DB::03, $DB::04, $DB::05) = $sth->fetchrow_array())
{
$DB::01 =~ s/\s//gi;
$DB::02 =~ s/\s//gi;
$DB::03 =~ s/\s//gi;
$DB::04 =~ s/\s//gi;
$DB::05 =~ s/\s//gi;

$TABLE::DATA .= "<tr>
<td>$DB::NULL</td>
<td>$DB::01</td>
<td>$DB::03</td>
<td>$DB::04</td>
<td>$DB::05</td>
<td>$DB::06</td>
<td>$DB::07</td>
</tr>";
$counter = $ counter + 1;
}
$sth->finish();
$dbh->disconnect();

--------------------------------

the output comes out ALL garbled!!!!!

i cant isolate the table name ~ type etc......

what is it that im doing wrong??? it access the DB correctly NO ERROS when connecting just the format is wrong.

Help!!!

- Scott

Wise men ask questions, only fools keep quite.
 
This might be a daft suggestion, but would it not make more sense just to make use of the standard MySQL module ported with Perl...


Paying particular attention to the section entitled 'Statement Handle'

As far as I can tell MySQLPP uses net::mysql as well so you should be able to get the table name and attributes by doing something along the lines of:
Code:
my @tables = $dbh->tables;
foreach my $table(@tables)  {
    my @field_names = $mysql->get_field_names($table);
    foreach my $field_name (@field_names)  {
       print $table."->".$field_name."\n<br>";
    }
}

Rob Waite
 
Waiterm,

Thanks!!!

Sorry it took me so long to look at this post i have been dealing with a few things. I am going to be looking into this and yes that makes ALOT of sense! I know that the way that im writting some of this code is the long way! And i appreshiate any and all help!

- Scott

Wise men ask questions, only fools keep quite.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top