I am trying to get 3 variables from a table row in MySQL and I am using two books for help and they say to use fetchrow_array or _arrayref to get it. I've tried it several ways as shown in the book but my server keeps responding with:
Can't locate object method "fetchrow_array" via package "DBI::db" (perhaps you forgot to load "DBI::db"?)Are there alternatives to getting the data out from MySQL and assigning it to a variable? Here's two of my last attempts
JayBee says Thanks for your help :)
use warnings;
use DBI;
use DBD::mysql;
use CGI qw( :standard );
use CGI::Carp "fatalsToBrowser";
print header, start_html('SQL Must Work!');
my $dbh = DBI->connect("DBI:mysql:data:server","uname","pass") or
die( "Could not make connection to database: $DBI::errstr" );
$dbh->do( qq{SELECT Tab1, Tab2, Tab3
FROM UData } );
while (my @row = $dbh->fetchrow_array ) {
my ( $item0, $item1, $item2 ) = @row;
if ($item0 >= $somevalue) {
print br, "$item0"; }
}
warn( $DBI::errstr ) if ( $DBI::err );
$dbh->disconnect();
print '<h2>All Done</h2>';
print end_html;
Here's another using STDOUT after SELECT - FROM -, to the disconnect:
my @array;
while (my @row = $dbh->fetchrow_array ) {
write ();
}
format STDOUT =
@<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<
$array[0], $array[1], $array[2]
.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.