valavanp has asked for the wisdom of the Perl Monks concerning the following question:
In DBI, I want to get the user input and fetch the rows given by user. I am getting only the last row of my table. But when i view it in MYSQL driver it shows all the rows. Can anyone tell where i am wrong. This is the coding which i executed.
use DBI; use strict; $a=<STDIN>; chomp $a; $b=<STDIN>; chomp $b; my $dbname="test"; my $dbh=DBI->connect("DBI:mysql:$dbname","root","", {RaiseError=>1, Au +toCommit=>0}); $sth=$dbh->do("create table rec(name varchar(10), id int(10)"); $sth=$dbh->prepare("insert into rec(name, id) values(?, ?)"); $sth->execute($a, $b); $sth->prepare("select * from rec"); my @row; while (@row=$sth->fetchrow_array) { print "@row\n"; } $sth->finish(); $dbh->disconnect(); exit;
Thanks for the help. Apologize if any errors.
20060711 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI giving user input by place holders
by gellyfish (Monsignor) on Jul 11, 2006 at 08:45 UTC | |
by valavanp (Curate) on Jul 11, 2006 at 12:05 UTC | |
by john_oshea (Priest) on Jul 12, 2006 at 15:43 UTC | |
|
Re: DBI giving user input by place holders
by Herkum (Parson) on Jul 11, 2006 at 13:12 UTC | |
by ptum (Priest) on Jul 11, 2006 at 15:05 UTC |