當試圖做到這一點:php pdo mysql fetch返回一般錯誤?
// make unread notifications
$db->sqlquery("SELECT `participant_id` FROM `user_conversations_participants` WHERE `conversation_id` = ? AND `participant_id` != ?", array($_POST['conversation_id'], $_SESSION['user_id']));
while ($participants = $db->fetch())
{
$db->sqlquery("UPDATE `user_conversations_participants` SET `unread` = 1 WHERE `participant_id` = ?", array($participants['participant_id']));
}
我似乎得到這個錯誤:
Warning: PDOStatement::fetch() [pdostatement.fetch]: SQLSTATE[HY000]: General error in /home/gamingon/public_html/prxa.info/includes/class_mysql.php on line 68
這裏是我的查詢和提取功能:
// the main sql query function
public function sqlquery($sql, $objects = array())
{
global $core;
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, (int)$p, PDO::PARAM_INT);
}
else
{
$this->STH->bindValue($k+1, $p, PDO::PARAM_STR);
}
}
$this->counter++;
return $this->STH->execute();
}
catch (Exception $e)
{
$core->message($e->getMessage());
}
}
public function fetch()
{
$this->STH->setFetchMode(PDO::FETCH_ASSOC);
**return $this->STH->fetch();**
}
你能突出顯示第68行嗎? – Baronth
爲什麼不使用'UPDATE ... SELECT'? – Kermit
我已經突出顯示像星星每邊68。 – NaughtySquid