I have a query that is run 1000s of times which I'm trying to optimize using prepared statements:
我有一个运行1000次的查询,我正在尝试使用预处理语句进行优化:
$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).
它似乎无法过滤掉HAVING子句中规定的条件(所以我得到的结果是股票小于100)。
Is this a bug / limitation to SQLite or am I doing something wrong?
这是对SQLite的错误/限制还是我做错了什么?
All my other queries work fine when converted into prepared statements...
我转换成准备好的语句时,我的所有其他查询都可以
1 个解决方案
#1
1
Try: $stmt->bindParam(2, $shares, PDO::PARAM_INT); $stmt->execute();
尝试:$ stmt-> bindParam(2,$ shares,PDO :: PARAM_INT); $ stmt->执行();
#1
1
Try: $stmt->bindParam(2, $shares, PDO::PARAM_INT); $stmt->execute();
尝试:$ stmt-> bindParam(2,$ shares,PDO :: PARAM_INT); $ stmt->执行();