0

I am trying to use a php string as a not in argument within a sql statement. The php string I wanted to use looks like the following:

$excludedValues = "test,these,origin"

I would like to use that string as an argument in the following sql:

$conn = $this->getEntityManager()
        ->getConnection();

    $sql = "SELECT u.name FROM user u WHERE u.name NOT IN(:names)";
    $stmt = $conn->prepare($sql);
    $stmt->execute(array('names' => $excludedValues));

    return $stmt->fetchAll();

The excludedValues are being ignored.. what am I doing wrong here?

Information: It is not an array, and even with using an array and implode, I couldn't get it to work.

Regards.

user3746259
  • 1,491
  • 2
  • 23
  • 46
  • updated information within the question. It is a string, and not an array of numbers. I already tried the same by exploding the string into a string array, and then using implode, but couldn't get it to work.. It is not a duplicate. – user3746259 Oct 20 '16 at 15:57
  • you should use trim() after exploding such a wrongly composed string – Your Common Sense Oct 20 '16 at 16:00
  • Already did that. The problem when using strings is, that the parameter of "not in" is expected to like like the following: .. NOT IN("test","these","origin").. and I don't know how to do that. – user3746259 Oct 20 '16 at 16:02
  • The sooner you realize this is a *most exact duplicate*, the sooner you will have your problem solved. check the link I posted – Your Common Sense Oct 20 '16 at 16:02
  • I'm trying with "call_user_func_array" now as described in the other post. sry, i was kind of confused right now. Thanks for your help. – user3746259 Oct 20 '16 at 16:09
  • you were kind of confused when tagged your post with mysqli while actually using PDO. So you don't need call_user_func_array at all. – Your Common Sense Oct 20 '16 at 16:14
  • Oh sheesh. I just wanted to Tag mysql..ha – user3746259 Oct 20 '16 at 16:32
  • Working when using "?" to bind parameters, thanks – user3746259 Oct 20 '16 at 16:41

0 Answers0