I think that wants to be 
prepare(q/SELECT * FROM logs where datetime like ?/)

i.e. no quotes around the ?. DBD::mysql is telling you there are no parameters
in the query -> "called with 1 bind variables when 0 are needed"

However, you might have problems doing a like on datetime field.

Martin
--
Martin J. Evans
Easysoft Ltd, UK
http://www.easysoft.com


On 09-Feb-2006 J.I. Asenjo wrote:
> Hi all,
> 
> I am retrieving some data from a syslog mysql database:
> 
>#!/usr/bin/perl
> use warnings;
># use strict;
> use DBI;
> 
> my $dbh = DBI->connect('dbi:mysql:syslog', 'user', 'passwd')
>     or die DBI->errstr;
> 
>       my $sth = $dbh->prepare("SELECT * from logs where host = ?"
>               or die $dbh->errstr;
> 
>               print "Enter host: ";
>               while ($host = <>) {
>                  my @data;
>                          chomp $host;
>                                  $sth->execute($host) or die $sth->errstr;
> 
> This works as expected, I am prompted to enter a hostname and get the
> results in the rest of the script which is not necessary to show
> because the error comes here:
> 
> if i substituet in my $sth
> 
>       my $sth = $dbh->prepare("SELECT * FROM logs where datetime like '?'")
>          or die $dbh->errstr;
>               print "Enter datetime: ";
>               while ($datetime = <>) {
>                  my @data;
>                          chomp $datetime;
>                                  $sth->execute($datetime) or die $sth->errstr;
> 
> then I am prompted to enter a date, which I can, but immediately after
> that:
> 
> DBD::mysql::st execute failed: called with 1 bind variables when 0 are
> needed at datetime.pl line 19, <> line 1.
> 
> The difference is in the SELECT like '?', I have tried like '%?%', but
> it does not work either. In fact I need '%?%' which is what really works
> for the mysql statement.
> 
> If I define $datetime beforehand and interpolate it in the query, it
> works, but I read here that it is not reccommended:
> 
> http://www.perl.com/pub/a/1999/10/DBI.html
> 
> Any help greatly appreciated, I continue reading perldoc DBD::mysql,
> perldoc DBI etc.
> 
> -- 
> Groeten,
> J.I.Asenjo

Reply via email to