Okay, so I've spent a couple days trolling google and finding absolutely nothing on this. Basically I'm using a prepared statement that has a couple joins and matches based on several LIKEs, an IN, and a FREETEXT. I'm building the query dynamically to support the IN condition. I think some code will help
public function searchForProjWithTags(Array $dSearchArgs, $dTags) {
$bSplitTags = preg_split ("/[,]/", $dTags);
$bCount = count($bSplitTags);
$bQuestionMarks = "?" . str_repeat (",?", $bCount-1);
$bSql = "SELECT DISTINCT Foo.Foo_ID, Foo.Blah1, Foo.Blah2, Foo.Blah3,
Foo.Blah4, Foo.Blah5, Foo.Blah6, Foo.Blah7, Foo.Blah8, Foo.Blah9,
Foo.Blah10
FROM Foo INNER JOIN
TaggedFoo ON Foo.Foo_ID = TaggedFoo.Foo_ID INNER JOIN
Tag ON TaggedFoo.Tag_ID = Tag.Tag_ID
WHERE Foo.Blah2 LIKE ?
AND Foo.Blah3 LIKE ?
AND Foo.Blah4 LIKE ?
AND Foo.Blah5 LIKE ?
AND Foo.Blah6 LIKE ?
AND Foo.Blah7 LIKE ?";
if($dSearchArgs["Blah8"] != "") {
$bSql .= "AND FREETEXT (Foo.Blah8, ?)";
}
$bSql .= "AND Tag.Tag_ID IN (" . $bQuestionMarks . ")
ORDER BY Foo.Blah2 ASC,
Foo.Blah3 ASC,
Foo.Blah5 ASC";
if(!$bStmt = $this->getPDO()->prepare($bSql)) {
print_r($this->getPDO()->errorInfo());
}
$bStmt->bindValue(1, "%" . $dSearchArgs ["Blah2"] . "%");
$bStmt->bindValue(2, "%" . $dSearchArgs ["Blah3"] . "%");
$bStmt->bindValue(3, "%" . $dSearchArgs ["Blah4"] . "%");
$bStmt->bindValue(4, "%" . $dSearchArgs ["Blah5"] . "%");
$bStmt->bindValue(5, "%" . $dSearchArgs ["Blah6"] . "%");
$bStmt->bindValue(6, "%" . $dSearchArgs ["Blah7"] . "%");
if($dSearchArgs["Blah8"] != "") {
$bStmt->bindValue(":s", $dSearchArgs["Blah8"]);
}
for($i = 0; $i < $bCount; $i ++) {
$bStmt->bindValue (7 + $i, $bSplitTags [$i]);
}
echo "<br><br>" . $bSql . "<br><br>";
$bStmt->debugDumpParams();
if(!$bStmt->execute()) {
print_r($bStmt->errorInfo());
}
return $bStmt->fetchAll(PDO::FETCH_ASSOC);
}
So, I've got some probes at the end there so I can see what's going on. These are their results: the echo of $bSql gives the whole SQL string, what should be sent to the DBMS. However, the debugDumpParams() chops off the statement at character 433, it literally end like "...AND Foo.Blah3 L". I have no idea why it would truncate after character 433 and in the middle of LIKE (no special chars, etc.).
The second print_r says Array ( [0] => IMSSP [1] => -29 [2] => Tried to bind parameter number 0. SQL Server supports a maximum of 2100 parameters. ). I have no idea what this means and google wasn't much help either.
So, anyone have any idea why this is happening? I've literally spent hours trying to find something without even coming close. If I run the query manually, it works.
For reference I'm using PHP version 5.4.21, Apache 2.4.6, php_pdo_sqlsrv_54_ts.dll as my PDO driver, and Microsoft SQL Server 2012.