重複の可能性:
LIMITのPHP PDO bindValue
さて、ここに私のクエリがあります:
$db->sqlquery("
SELECT a.*, c.`category_name`
FROM `articles` a LEFT JOIN `articles_categorys` c
ON c.`category_id` = a.`category_id`
WHERE a.`active` = 1
AND a.`category_id` IN (?)
ORDER BY a.`date`
DESC LIMIT ?", array($config['article_rss_categorys'], $limit)
);
確認すると、$config['article_rss_categorys']
が設定され、その0,1,2,4,6,7
、も$limit
設定され、15
です。
これが私のクエリコードです
try
{
$this->STH = $this->database->prepare($sql);
foreach($objects as $k=>$p)
{
// +1 is needed as arrays start at 0 where as ? placeholders start at 1 in PDO
if(is_numeric($p))
{
$this->STH->bindValue($k+1, $p, PDO::PARAM_INT);
}
else
{
$this->STH->bindValue($k+1, $p, PDO::PARAM_STR);
}
}
return $this->STH->execute();
$this->counter++;
}
catch (PDOException $e)
{
$core->message($e->getMessage());
}
なぜ失敗しているのかわかりませんが、愚かなことを見逃しているのでしょうか?
phpmyadminでクエリをテスト?
し、正しいものに置き換えました。データベースが正常に機能するように機能します。
次に、そのように結果を取得して出力しようとします。
while ($line = $db->fetch())
{
// make date human readable
$date = $core->format_date($line['date']);
$output .= "
<item>
<title>{$line['category_name']} > {$line['title']}</title>
<link>http://www.prxa.info/index.php?module=articles_comments&aid={$line['article_id']}</link>
<pubDate>{$date}</pubDate>
<guid>http://www.prxa.info/index.php?module=articles_comments&aid={$line['article_id']}</guid>
</item>";
}
これは私のフェッチコードです:
public function fetch()
{
$this->STH->setFetchMode(PDO::FETCH_ASSOC);
return $this->STH->fetch();
}