1

This is the code I used to far:

$stmt = $pdo->prepare('SELECT name, age, something FROM MyTable WHERE MATCH (name, age) AGAINST (:value IN BOOLEAN MODE)');
$stmt->bindParam(':value', $value, PDO::PARAM_STR);
$stmt->execute();
$results = $stmt->fetchAll();
foreach( $results as $row ) {

It's working very well. But now I want to add date >= :date in the query.

I changed the code like this:

$stmt = $pdo->prepare('SELECT name, age, something FROM MyTable WHERE MATCH (name, age) AGAINST (:value IN BOOLEAN MODE) AND date >= :date');
$stmt->bindParam(':value', $value, PDO::PARAM_STR);
$stmt->execute(array(':date' => $date));
$results = $stmt->fetchAll();
foreach( $results as $row ) {

But I'm always getting this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in /var/www/username/html/folder/file.php:136 Stack trace: #0 /var/www/username/html/folder/file.php(136): PDOStatement->execute(Array) #1 {main} thrown in /var/www/username/folder/keywords.php on line 136

What am I doing wrong?

Machavity
  • 30,841
  • 27
  • 92
  • 100

3 Answers3

1

Let me see if I can clarify the other hints.

$stmt->bindParam(':value', $value, PDO::PARAM_STR);

This is binding :value. You already get that

$stmt->execute(array(':date' => $date));

This line is overwriting the previous line. In other words, execute is overwriting anything you've previously defined using bindParam. So bind them all using bindParam or bind them all using execute. You can't mix and match

Machavity
  • 30,841
  • 27
  • 92
  • 100
0

Use

$stmt->bindParam(':date', $date); instead of passing array to execute()

Sylwit
  • 1,497
  • 1
  • 11
  • 20
  • And what to do with `(':value_final', $value_finial, PDO::PARAM_STR)`? –  Aug 27 '16 at 14:33
0

That was the solution:

$stmt->bindParam(':value_final', $value_finial, PDO::PARAM_STR);
$stmt->bindParam(':date', $date);