Search code examples
phpmysqlpdobindparam

PHP, MySQL: Issue with bindParam


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?


Solution

  • That was the solution:

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