Trying to access DB
am 05.09.2007 13:34:57 von JimJx
Hi all,
I am trying to access a DB using a select statement and am having a
little problem.....
I connect fine, but I just can't seem to pull any data out. The
script I am using is below...
I know it is running the script because it is printing out the ToEdit:
$ToEdit
Any suggestions greatly appreciated.
Jim
if ($Enter) {
my $dbh = DBI->connect('DBI:mysql:farthing_valleyweb',$DBuser,
$DBpass)
or die "Couldn't connect to database: " . DBI->errstr;
my $sth = $dbh->prepare('SELECT * FROM valley WHERE Name LIKE "%$ToEdit
%"') or die "Cannot prepare: " . $dbh->errstr();
$sth->execute()
or die "Couldn't execute statement: " . $sth->errstr;
while ($thisvalue = $sth->fetchrow()) {
push @thisarray, $thisvalue;
};
$dbh->disconnect;
foreach (@thisarray) {
print @thisarray . "
";
}
print "ToEdit: $ToEdit\n";
exit;
}
Re: Trying to access DB
am 05.09.2007 15:01:18 von jluis
In article <1188992097.892868.179390@k79g2000hse.googlegroups.com>, JimJx
wrote:
> my $sth = $dbh->prepare('SELECT * FROM valley WHERE Name LIKE "%$ToEdit
> %"') or die "Cannot prepare: " . $dbh->errstr();
>
my $sth = $dbh->prepare
('SELECT * FROM valley WHERE Name LIKE "%'.$ToEdit.'%"') Or die
'Cannot prepare: ' . $dbh->errstr();
Re: Trying to access DB
am 05.09.2007 15:39:44 von Peter Scott
On Wed, 05 Sep 2007 04:34:57 -0700, JimJx wrote:
> my $dbh = DBI->connect('DBI:mysql:farthing_valleyweb',$DBuser,
> $DBpass)
> or die "Couldn't connect to database: " . DBI->errstr;
>
> my $sth = $dbh->prepare('SELECT * FROM valley WHERE Name LIKE "%$ToEdit
> %"') or die "Cannot prepare: " . $dbh->errstr();
>
> $sth->execute()
> or die "Couldn't execute statement: " . $sth->errstr;
my $dbh = DBI->connect( 'DBI:mysql:farthing_valleyweb', $DBuser, $DBpass,
{ PrintError => 0, RaiseError => 1 } )
or die "Couldn't connect to database: " . DBI->errstr;
my $sth = $dbh->prepare( 'SELECT * FROM valley WHERE Name LIKE ?' );
$sth->execute( "%$ToEdit%" );
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
Re: Trying to access DB
am 05.09.2007 17:26:49 von JimJx
Thanks for the replies!
Jose, for some reason, your gave me errors when I executed it.....
Peter, works like a charm!
Thanks again to both for taking the time to reply,
Jim
Re: Trying to access DB
am 06.09.2007 08:49:31 von jluis
In article <1189006009.457673.103820@g4g2000hsf.googlegroups.com>,
JimJx wrote:
> Jose, for some reason, your gave me errors when I executed it.....
>
The newsreader that I'm using capitalizes letters after the dot and the
or operator was changed to Or.