punchcard_bob has asked for the wisdom of the Perl Monks concerning the following question:
Could someone please point out where I'm going wrong with the following code?
Supposed to be the abc's of sql under DBI::CSV, I want to count the number of records in a csv file (yes, properly created under DBI::CSV - the database is known to work) that contain a certain user_name.
But, the following dies at the prepare statement and produces a "parse error near (*)" error:
so I tried brute force:$sqlCount = "SELECT COUNT(*) FROM $user_data_db_name WHERE USER_NA +ME='$form_values{'USER_NAME'}'"; $sth = $dbh->prepare($sqlCount) || die "Cannot prepare: " . $dbh-> +errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); my $occurences = $sth->fetchrow_arrayref->[0];
which runs, but returns null for $ocurrences.$sqlCount = "SELECT * FROM $user_data_db_name WHERE USER_NAME='$fo +rm_values{'USER_NAME'}'"; $sth = $dbh->prepare($sqlCount) || die "Cannot prepare: " . $dbh-> +errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); $sth->finish(); $ocurrences = 0; while (@data = $sth->fetchrow_array()) { $ocurrences++; }
Hours of searching for ideas has produced nothing.
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI : select count
by lachoy (Parson) on May 09, 2002 at 16:19 UTC | |
|
Re: DBI : select count
by tommyw (Hermit) on May 09, 2002 at 16:21 UTC | |
by VSarkiss (Monsignor) on May 09, 2002 at 17:10 UTC | |
by punchcard_bob (Initiate) on May 09, 2002 at 17:29 UTC |