开发者

PHP PDO and IN clause

I have a statement being used with PDO which is as follows:

$stmt = _DB::init()->prepare("SELECT a.*
                              FROM tax_class a
                              INNER JOIN products_to_tax_class pa 
                              ON a.tid = pa.tid
                              WHERE pa.pid IN (1,2)
                             ");

Now the statement gets executed, however it only grabs results for pa.pid = 2, or the last value of the ones given. Would anyone be able to explain this for me? I was expecting an array of results from both id's 1 and 2 however this only outputs Array ( [tid] => 2 [rate] => 7.30 [name] => Something )

if ($stmt->execute开发者_开发百科())
          return $stmt->fetch(PDO::FETCH_ASSOC);

Thanks


$stmt->fetch only fetches one row at a time. Use fetchAll to return the entire result set


It looks like you're only calling fetch once. This means you're getting the first row from the query and no more.

Try:

$stmt->fetchAll(PDO::FETCH_ASSOC);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜