Guest User

Untitled

a guest
Jun 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. (...)
  3. $query = '
  4. SELECT SQL_CALC_FOUND_ROWS
  5. k.id,
  6. k.name,
  7. FROM
  8. kantoren AS k
  9. WHERE
  10. ' . (! empty($this->vars['name']) ? 'AND k.name LIKE ?' : '1') . '
  11. GROUP BY
  12. k.id
  13. ORDER BY
  14. k.name';
  15.  
  16. $tokens = array();
  17.  
  18. foreach ($this->vars as $key => $var) {
  19. if (!empty($var)) $tokens[] = $var;
  20. }
  21.  
  22. $this->results = Zend_Registry::get('database')->query($query, $tokens);
  23.  
  24. /*
  25. If I have this:
  26. $this->vars['name'] = "a%";
  27. ... I get a mysql error, because it's missing the quotes around it. (needs to be LIKE "a%", actualy is LIKE a%)
  28.  
  29. If I have this:
  30. $this->vars['name'] = " 'a%' ";
  31. ... I get a mysql error, because the quotation mark gets shashed (LIKE \'a%\')
  32. */
Add Comment
Please, Sign In to add comment