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

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!!!


Wise men ask questions, only fools keep quite.
 
Unix -

First im using GLOBAL variables '::' -

And in any case, as per your suggestion - I reset the variables and SAME output.....

- Scott

Wise men ask questions, only fools keep quite.
 
Not really a MySQL issue. Did you consider posting to the perl forum?
 
Eric,

Yes i did - i posted there as well - no reply - im figureing its the way MySQL returns the data, IE if you do a SHOW COLUMNS FROM table_name at the command prompt of MySQL there is some funny formatting going on.... UNLIKE when you do a SHOW TABLE; or SHOW DATABASES.

Thought maybe someone else here had tried this beofre and was successfull in grabing the correct data -

I check on MySQL page - and there is a comment:

when querying like:


SHOW columns FROM table
if you load the result in an array it will look like this:
array([0],[Field],[1],[Type],[2],[Null],[3],[Key],[4],[Default],[5],[Extra])
Where the number, [x], gives the same value as the name, [name].

well as a link to a PHP script that does this:


- however im not familar with PHP - and im not quite sure how to redo it into perl.




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

Part and Inventory Search

Sponsor

Back
Top