0

I'd like to bind values to a MSSQL "Contains" clause. The result should look as follows:

SELECT * FROM [aTable] WHERE CONTAINS(name, '"miller*") 

I tried the following way:

$sql = "SELECT * FROM [aTable] WHERE CONTAINS(name, '":name*"')";

and later on... (is a symfony2 project)

$stmt = $em->getConnection()->prepare($sql);
$stmt->bindValue('name', 'miller');

but unfortunately it doesn't work. Error:

pdo invalid parameter number parameter was not defined

It there a way to achieve this? Thank you!!

UPDATE: I ended up with the following. I prepare the CONTAINS argument before and then bind it to the parameter:

$sql = "SELECT * FROM [aTable] WHERE CONTAINS(name, :values)";
$contains_args_string = '"Mil*" AND "Joh*"';
$stmt = $em->getConnection()->prepare($sql);
$stmt->bindValue(':values', $contains_args_string, \PDO::PARAM_STR);
user1915746
  • 466
  • 4
  • 16

0 Answers0