> 
>$dbh=DBI->connect("DBI:mysql:database=mysql:table=user;host=127.0.0.1;port=3306",edhunter,<mypassword>);
> 
> @data = $dbh->fetchrow_array;

You can use the fetch* methods only on statement handles, so you have to 
prepare a statement-handle (sth) first 

$dbh=DBI->connect("DBI:mysql:database=mysql:table=user;host=127.0.0.1;port=3306",edhunter,<mypassword>);
### Check if the dbh is OK
die "No connect" if !$dbh;
### Prepare a statement handle (which mostly is a select, insert, update or delete)
$sth = $dbh->prepare("SELECT funny,thing FROM wonder");
### Check if the prepare worked and execute the query
if ($sth && $sth->execute()) {
    ### Now fetch the returned rows from the db
    @data = $dbh->fetchrow_array();
}

Hope this helps

Instead of using the prepare, execute, select you can also use the 
fetchall_* methods. But it would be better to understand the above before.

Good luck

-- 
+rl
-------------------------------------
Roland Lammel
-------------------------------------
Services / Technical Assistance / PPA
Kapsch AG, CarrierCom 
Wagenseilgasse, A-1121 Wien
-------------------------------------
mailto:[EMAIL PROTECTED]
Tel:   +43 1 60501 - 3456
Fax:   +43 1 60501 - 3405
Mobil: +43 664 628 - 3456
-------------------------------------

Matthew Harrison wrote:
> 
> 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=127.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

Reply via email to