Re: bind_param oddity?



Kevin Spencer wrote:
Hi guys,

I'm sure I'm missing something *very* obvious but this one has me
scratching my head. Using DBI 1.52, DBD::mysql 3.0007, Perl 5.8.8,
MySQL 5.0.18.

The following code executes fine:

my $table = 'CCHISTORY';
my $status = 'D';
my $limit = 86400;

my $SQL = <<EOSQL;
select count(*) from $table
where TRXSTATUS = '$status'
and (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(TRXTIMESTAMP)) < $limit
EOSQL

my $sth = $dbh->prepare($SQL) || die $DBI::errstr, "\n";
$sth->execute() || die $sth->errstr(), "\n";

Now, because I want use use placeholders instead, I attempt the following:

my $SQL = <<EOSQL;
select count(*) from ?
where TRXSTATUS = ?
and (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(TRXTIMESTAMP)) < ?
EOSQL

You can't use place holders for table names or column selectors.

my $sth = $dbh->prepare($SQL) || die $DBI::errstr, "\n";

my $table = 'CCHISTORY';
my $status = 'D';
my $limit = 86400;

my @bindParams = ($table, $status, $limit);
$sth->execute(@bindParams) || die $sth->errstr(), "\n";

Which fails with:

You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server for the right syntax to use near
''CCHISTORY'
and TRXSTATUS = 'D'
and (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(TRXTIMEST' at line 1

Anyone see an obvious error in my code that I'm overlooking?

Thanks.

--
Kevin.

Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com
.



Relevant Pages

  • bind_param oddity?
    ... Using DBI 1.52, DBD::mysql 3.0007, Perl 5.8.8, ... where TRXSTATUS = '$status' ... You have an error in your SQL syntax; ... corresponds to your MySQL server for the right syntax to use near ...
    (perl.dbi.users)
  • Re: bind_param oddity?
    ... Also you would leave your DB wide open to SQL insertion attacks if one could ... The following code executes fine: ... where TRXSTATUS = '$status' ... You have an error in your SQL syntax; ...
    (perl.dbi.users)
  • Re: Error connection Clarion 5.5G and MySQL
    ... I work with Clarion 5.5G and MSACCESS databases. ... I like to change my MSACCESS database to MYSQL 5.0 database, ... when I select a client I blocked this client for security and use a ... Error (You have an error in your SQL syntax: ...
    (comp.lang.clarion)
  • Re: Problem with apostrophe in MySQL
    ... "You have an error in your SQL syntax; ... corresponds to your MySQL server version for the right syntax to use ...
    (alt.php)
  • Re: MAINFRAME SHOP STANDARDS
    ... with a pretty nice drawing tool (I've used it to create database ... from the M/F IDE I generate SQL syntax and do a ... > copy and paste into COBOL source. ... MySQL has some new tools that let you develop the query against your ...
    (comp.lang.cobol)