Вопрос

i have a problem with the F3 Framework.

I'm trying to search for some text, which was typed by the user.

Here some statement:

$db->exec(array("Select userid,username,section from user 
          WHERE section=:sectionId 
          AND username ILIKE '%?%'"),
          array(':sectionId' => $sectionId),
          array( 1=> $queryString),
          NULL));

If there is some typo sorry, but i'm not allowed to post code from a productive system.

This statement return an empty array.

I have replaced the variables with Strings and tested it with psql, but it returns one match.

Someone an idea?

Edit:

Answer From Sn0opy:

$db->exec(array("Select userid,username,section from user 
            WHERE section=:sectionId 
            AND username ILIKE '%?%'"),
            array(':sectionId' => $sectionId, 1 => $queryString));

The Problem is, in Postgresql it is $1,$2,$3 and not '?' .

My Solution (thanks again to Sn0opy for his reply) :

You have to concat the the String

('%'|| :queryString || '%')

This works now :

$db->exec(array("Select userid,username,section from user 
            WHERE section=:sectionId 
            AND username ILIKE ('%'|| :queryString || '%') ),
            array(':sectionId' => $sectionId, ':queryString' => $queryString));

If you don't concat the String, you will get this error :

ERROR:  could not determine data type of parameter $1
Это было полезно?

Решение

You got this code right from the docs. If you recheck the docs, you will see the first array has three elements. So does the second. In your case, you have one element in the first and 3 in the last. Only the first parameter array(':sectionId' => $sectionId) will be applied.

This one should work:

      $db->exec(array("Select userid,username,section from user 
                WHERE section=:sectionId 
                AND username ILIKE '%?%'"),
                array(':sectionId' => $sectionId, 1 => $queryString));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top