title: CakePHP SQL Prepared Statements
body: <p>I've finally gotten jQuery AutoComplete to work with CakePHP. My initial plan was to have a grouped/categorised list, if the user enters the name of the school it will display all of that school's shows and if they enter the name of the show it will show the school that it is from. </p>
  
  <p>I found this very hard to get implemented using Cake syntax so I decided to concatenate the name of the school and the name of the show and then compare that string to the $term. I realised VirtualFields would not work across multiple models so adopted using prepared statements, the syntax itself evaluated fine but I get this SQL error:</p>
  
  <pre><code>"Column not found: 1054 Unknown column 'romeo and juliet' in 'where clause'"
  </code></pre>
  
  <p>So it seems to pass the term fine but compares it to the column name rather than the record. Here is the syntax for my AutoComplete function with the prepared statement:</p>
  
  <pre><code> public function autoComplete() {
      $this-&gt;autoRender = false;
      $term = $_GET['term'];
      $shownames = $this-&gt;Order-&gt;Show-&gt;query(
          'SELECT CONCAT(sm_schools.title, " - ", sm_shows.title)
          FROM sm_shows
          LEFT JOIN sm_schools
          ON sm_shows.school_id = sm_schools.id
          WHERE CONCAT(sm_schools.title, " - ", sm_shows.title) LIKE ' .$term
      );
      echo json_encode($this-&gt;_encode($shownames));
  }
  </code></pre>
  
  <p>Any help would be great.
  Thanks</p>