0

I saw the similar question, however it does not help me. I have this here PHP:

//looping array contains one value - below line not part of code, just for to expmplify
var_dump($categoriesBind) -> array(1) { [0]=> &string(10) "healthcare" } 


$sqlPS->bindParam(':belonging', $_GET['belonging']);
$sqlPS->bindParam(':title', $_GET['title']);
//variable number of parameters
for ($i = 0; $i < count($categoriesBind); $i++){
    $sqlPS->bindParam(':'.$categoriesBind[$i], $categoriesBind[$i]);
}

The resulting string from that is this:

SELECT * FROM blog_article 
WHERE belonging = ':belonging' 
AND blog_article.title != ':title' 
AND category LIKE '%:healthcare%' 
ORDER BY FIND_IN_SET(':healthcare',category) desc LIMIT 0,3

That returns array(0){}

However if i run the query with the filled in parameters manually, it runs fine and returns results. The ':belonging' and ':title' parameters bind fine, the problem is in the other binding interpretations and i can not, for the life of me, figure out what's going on.

UPDATE: upon further testing this is what fails '%:healthcare%'. The parameters do not bind inside the LIKE syntax.

If more info is needed, please ask.

Radu Andrei
  • 1,075
  • 10
  • 19
  • You need to change `healthcare` to `%healthcare%` in the original array. – Mike Jun 19 '15 at 19:58
  • Well, in the DB the column contains `'healthcare'`, no percentages. Will it match still? – Radu Andrei Jun 19 '15 at 20:00
  • Right, got it. Will mark for closure. Thank you. – Radu Andrei Jun 19 '15 at 20:01
  • The percentage signs are wildcards, which means that it matches any string. So if you have `World's best healthcare system` and you do `WHERE column LIKE `%healthcare%` it will match that row. The percentage signs are not in the original value. – Mike Jun 19 '15 at 20:05

0 Answers0