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?

1
  • 2
    Either use bindParam or pass all parameter in the execute(array) dont mix the 2 methods Commented Aug 27, 2016 at 14:26

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I'll try and get back later.
0

Use

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

1 Comment

And what to do with (':value_final', $value_finial, PDO::PARAM_STR)?
0

That was the solution:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.