Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Reading a MySQL table into an array

by rnahi (Curate)
on Jul 30, 2005 at 11:59 UTC ( #479600=note: print w/replies, xml ) Need Help??

in reply to Reading a MySQL table into an array

It seems to me that you are :

  • going into an unnecessarily complex path
  • mixing up instructions to deal with simple arrays and bi-dimensional ones.

A simpler solution should be:

my $tables = $dbh->selectcol_arrayref("SHOW_TABLES") or die $DBI::errstr;

This one, and many more are shown in DBI Recipes.

Be sure to understand the various idioms before using them. One introduction to what to get from a database is shown in The fine art of database programming.

And, don't forget to "use strict" and warnings.

Replies are listed 'Best First'.
Re^2: Reading a MySQL table into an array
by rvosa (Curate) on Jul 30, 2005 at 15:25 UTC
    use SQL; my @tables; my $temp; SQL::Connect "debloat", "localhost"; SQL::xqt "SHOW TABLES"; my $i = 0; while ($temp = $SQL::sth->fetchrow_arrayref){ $tables[$i] = $$temp[$i]; } foreach (@tables) { print "$_\n"; }
    If this is the exact same code you're using it would seem that you only get one entry because you don't update $i++.
      Sorry - I was trying to cut my code down to the minimum & cut too much! I'll check this out (as I said in another reply, my intention is to understand), but I have deleted some of my code after following RNahi's advice and getting a working solution.


      John Davies
Re^2: Reading a MySQL table into an array
by davies (Parson) on Jul 30, 2005 at 15:23 UTC
    Thanks. I couldn't immediately see how to do what I want with your solution, but the DBI recipes reference gave me everything I needed. I'll keep trying with your advice, though, as the purpose is to understand (the live DB & VB front end has been supporting about 20 users for about 18 months). I'm still rather mixed up about the array instructions, but I expect that I'll be able to sort myself out with more reading.

    I am using strict, warnings and diagnostics in all my files. If I didn't mention it in my somewhat rambling post, my apologies.


    John Davies

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://479600]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2018-06-18 20:24 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.