tags:

views:

306

answers:

1

I have a query that is run 1000s of times which I'm trying to optimize using prepared statements:

$query = "SELECT day, ticker, SUM(score*mod) as shares FROM indicators, modifiers WHERE indicators.dex=modifiers.dex AND ticker='$t' GROUP BY day, ticker HAVING shares>=$s";

When I run the query normally:

$transactions = $dbm->query($query);

I get the desired result set.

However, when I convert it into a prepared statement

$stmt = $db->prepare("SELECT day, ticker, SUM(score*mod) as shares FROM indicators, modifiers WHERE indicators.dex=modifiers.dex AND ticker=? GROUP BY day, ticker HAVING shares>=?");

and run:

$stmt->execute(array($t, 100));

it seems that it is unable to filter out the condition stated in the HAVING clause (so I get results where shares are less than 100).

Is this a bug / limitation to SQLite or am I doing something wrong?

All my other queries work fine when converted into prepared statements...

+1  A: 

Try: $stmt->bindParam(2, $shares, PDO::PARAM_INT); $stmt->execute();

Noah