3
votes

I wrote this fulltext search function, but it throws me this error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1.

I am new to OOP & PDO, is my prepare statement in the correct syntax ? Or did i go wrong anywhere else ? Did I implement the :q parameter right in the query ?

 public function searchFullTextPanel($q)
 {
  try
  {
   $stmt=$this->db->prepare("SELECT id,firstname,lastname,adresse_str,adresse_plz,adresse_ort,adresse_land,telefon,email,image_name FROM partner WHERE MATCH (firstname,lastname,adresse_str,adresse_plz,adresse_ort,adresse_land,telefon,email) AGAINST :q");

   $stmt->bindparam(":q",$q);
   $stmt->execute();

           if($stmt->rowCount()>0)
          {
       while($row=$stmt->fetch(PDO::FETCH_ASSOC))
       {
        // doing stuff
       }
      }
  else
  {
   ?>
   <tr>
   <td>fml...</td>
   </tr>
   <?php
  }
 }
 catch(PDOException $e)
  {
   echo $e->getMessage(); 
   return false;
  }
 }
1

1 Answers

2
votes

AGAINST :q Should be AGAINST (:q)