1

Params:

$params = 2826558;                        # Necessary Object
$params = array(2826558,2677805,2636005); # NULL

Execution code:

    $data = $this->DQL_selectAllByCampaign_id()
                 ->execute( array($params) )
                 ->fetchAll();

    var_dump( $data );

SQL Query:

$this->DQL_selectAllByCampaign_id = $this->conn->prepare(

        "SELECT * FROM `banner` WHERE  `campaign_id` IN (?)"

);

If $params is Integer, returns necessary Object. If $params is Array, returns NULL.

After all, in fact it should work... How can I do that?

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
ajile
  • 666
  • 1
  • 10
  • 18
  • 4
    See http://stackoverflow.com/questions/920353/php-pdo-can-i-bind-an-array-to-an-in-condition – Andrew Jul 30 '10 at 18:27
  • Unfortunately I did not have access to PDO Object directly, I have only $this->DQL_selectAllByCampaign_id() wrapped method to `quote` current array value. I tried to implode(',',$params);, but unsuccesfully, receiving only row by id in first element of array. – ajile Jul 30 '10 at 18:54

1 Answers1

1

I'm quite sure this isn't the 'right' answer, but we solved this by adding in count($array) placeholders. Then using call_user_func_array we pass the params in.

Thanks for asking this - will be interesing to find out what the proper way to do this is...

kander
  • 4,226
  • 1
  • 22
  • 43
  • I found the solution of which you speak - http://www.php.net/manual/en/pdo.prepare.php. Apparently this is really the most common solution. But it is a crutch. I'll look for a solution more beautiful than this, and yet do so. – ajile Jul 30 '10 at 18:47