0
下面是一個功能,旨在處理自定義類的搜索方案。我的PDO綁定如何仍然搞亂我的查詢?
我已經絆倒了PDO默認綁定參數爲字符串的事實,即使它不合適也會導致整數 - >字符串轉換。正如你將會看到的那樣,我通過手動檢查類型是否是整數,然後在這種情況下強制使用int來糾正這種情況。問題是,我的解決方案只適用於'開始'值爲0 - 任何更高的錯誤,我不知道爲什麼。如果我手動將開始/計數值設置爲其適當的值(即,而不是:count,我使用{$ count}),一切正常,所以看起來綁定仍然搞亂。
怎麼樣?或者如果我錯了......什麼是對的?
/*Query is:
SELECT tutor_school.id
FROM tutor_school, tutor_states
WHERE tutor_states.stateName=:state AND tutor_states.id=tutor_school.state
GROUP BY tutor_school.id order by tutor_school.name asc
LIMIT :start, :count*/
$db = Database::get_user_db();
$statement = $db->prepare($query);
foreach ($executeArray as $key => $value)
{
if (getType($value) == 'integer')
{
$statement->bindParam($key, $executeArray[$key], PDO::PARAM_INT);
}
else
{
$statement->bindParam($key, $value);
}
}
var_dump($executeArray);//count and start are still ints
if ($statement->execute())
{
var_dump($executeArray);//start and count are now strings
var_dump($statement->errorInfo());
var_dump($query);
$values = $statement->fetchAll();
$return = array();
foreach ($values as $row)
{
$school = School::schoolWithId($row[0]);
if (!empty($school))
{
$return[] = $school;
}
}
return $return;
}
..解釋爲什麼在這個問題上有這麼多的線程。那麼,至少真的很容易清理數據,應該是一個整數... – RonLugge 2012-07-17 05:00:43