Can't be from the book, because this is totally wrong. You forgot the
prepare method between connect and fetchrow_array, also fetchrow array,
has to be called on a statement handle.
my $dbh = DBI->connect(....);
my $sth = $dbh->("select * from foo");
my @data = $sth->fetchrow_array();
Ilya
> -----Original Message-----
> From: Matthew Harrison [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 20, 2002 10:25 PM
> To: [EMAIL PROTECTED]
> Subject: basic dbi functions
>
>
> i am very new to perl and i am experimenting with databases.
> I have written
> a little script just to connect to a MySQL database, get a
> row and print
> it. this is what i have:
>
> #!/usr/bin/perl
>
> use CGI::Carp "fatalsToBrowser";
> use CGI ":all";
> use DBI;
> use CGI qw/:standard/;
>
> $dbh = new CGI;
> $dbh=DBI->connect("DBI:mysql:database=mysql:table=user;host=12
7.0.0.1;port=3306",edhunter,<mypassword>);
>
> @data = $dbh->fetchrow_array;
>
> $host = \@data[0];
>
> print <<END_OF_HTML
> content-type: text/html
>
> <HTML>
> <HEAD><TITLE>mats first database program</TITLE></HEAD>
> <BODY>result: $host</BODY>
> </HTML>
>
> END_OF_HTML
>
> everything is either from my Perl in a Nutshell book or from
> perldoc.com.
> When i run this, i am getting:
>
> Can't locate object method "fetchrow_array" via package "DBI::db" at
> /web/misc/perl-lessons/database.cgi line 11.
>
> what is wrong with it???
>
> --
> Matthew Harrison
> Internet/Network Services Administrator
> Peanut-Butter Cheesecake Hosting Services
> Genstate
> www.peanutbuttercheesecake.co.uk
>