larry lefthook wrote:
> Hi! What's the right syntax using a variable with Perl & MySQL query?
> I got an example for PHP:
> #$exp_time = time()-86400;
> #$query = "DELETE FROM cl_temp_users WHERE sign_up_date < $exp_time;" ;
> But with Perl it does not work, like I have tried below. How to put my 
> $sth line with prepare right so that I can use $exp_time2 in query? I 
> tried:my $sth = $dbh->prepare('delete from cl_items WHERE "date_time < 
> $exp_time2" ');, But with ""s nothing happens to my table. So I want 
> records older than 1day removed from table. My CODE:
> 
> #!/usr/bin/perl -w
> 
> use DBI;
> my $dsn = 'dbi:mysql:deClass:localhost:3306';
> my $user = 'somebody';
> my $pass = 'someword';
> 
> my $dbh = DBI->connect($dsn, $user, $pass)
>        or die "Cant connect to the DB: $DBI::errstr\n";
> 
> my $exp_time2 = time()-86400;
> 
> my $sth = $dbh->prepare('delete from cl_items WHERE date_time < 
> $exp_time2 ');
> 

You are single quoting your statement which means $exp_time2 is taken 
literally rather than interpolated should be:

my $sth = $dbh->prepare("delete from cl_items WHERE date_time < 
$exp_time2 ");

> $sth->execute();
> 

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to