0
$prepare=$text->prepare("
  select *
  from (
    select text1,text2
    from test1
  union
    select text1,text2
    from test2
  ) as u
  where u.text1 in (?,?)");
$prepare->execute($array);
$fetch=$prepare->fetch(PDO::FETCH_ASSOC);
print_r($fetch);

I have a PDO statement that uses UNION, WHERE and IN all in one. This should be returning a few results. The array contains all datapoints. What might be the issue in the statement?

Maciek Semik
  • 1,872
  • 23
  • 43

1 Answers1

0

In prepared statements, in IN clause you need to construct the query yourself. See this post for more information. If you got an error, please edit your post and include the error msg.

EDIT:

//Correct use of fetch statement:
$prepare->execute($array);
$results = array();
while( $fetch=$prepare->fetch(PDO::FETCH_ASSOC) ){
    $results[] = $fetch;
}
print_r($results);
Community
  • 1
  • 1
Emiliano Sangoi
  • 921
  • 10
  • 20