Trying to access DB

J

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 . "<br />";
}
print "ToEdit: $ToEdit\n";
exit;
}
 
P

Peter Scott

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%" );
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top