我想问下面的SELECT Class, Race ......
查询有什么问题。它会触发DB_ERROR
$db = $this->database[GDB];
$character = $this->site->SanitizeName($_POST['character']);
$num_rows = $db->doQuery('SELECT bNation FROM ACCOUNT_CHAR WHERE strAccountID = ? AND ? IN(strCharID1, strCharID2, strCharID3)', $_SESSION['strAccountID'], $character);
if ($num_rows == -1)
{
$db->GetError(__file__, __line__);
$this->m_ccError = Template::GetLangVar('DB_ERROR');
return false;
}
else if ($num_rows == 0)
{
$this->m_ccError = Template::GetLangVar('CC_INVALID_ACCOUNT');
return false;
}
$row = $db->doRead();
$nation = $row['bNation'];
$num_rows = $db->doQuery('SELECT Class, Race, Strong, Sta, Dex, Intel, Cha, Points, TransferTime FROM USERDATA u LEFT JOIN PREMIUM_SERVICE p ON p.strAccountID = ? WHERE strUserId = ? AND (TransferTime < IF(p.strAccountID IS NULL, DATEADD(DAY,-2,GETDATE()), DATEADD(MINUTE,-30,GETDATE())) OR TransferTime IS NULL) AND zone<>199 and authority<>255', $_SESSION['strAccountID'], $character);
if ($num_rows == -1)
{
$db->GetError(__file__, __line__);
$this->m_ccError = Template::GetLangVar('DB_ERROR');
return false;
}
else if ($num_rows == 0)
{
$this->m_ccError = Template::GetLangVar('CC_RECENT_TRANSFER');
return false;
}
如果我在下面使用它,它运作良好。我添加了高级检查,因此请检查下面的最后一个不想正常工作。
$num_rows = $db->doQuery('SELECT Class, Race, Strong, Sta, Dex, Intel, Cha, Points, TransferTime FROM USERDATA WHERE strUserId = ? AND (TransferTime < DATEADD(DAY,-2,GETDATE()) OR TransferTime IS NULL) and zone<>199 and authority<>255', $character);
但是如果我在下面使用这个..它会触发$num_rows == -1
并显示上面主函数中的DB_ERROR
。
$num_rows = $db->doQuery('SELECT Class, Race, Strong, Sta, Dex, Intel, Cha, Points, TransferTime FROM USERDATA u LEFT JOIN PREMIUM_SERVICE p ON p.strAccountID = ? WHERE strUserId = ? AND (TransferTime < IF(p.strAccountID IS NULL, DATEADD(DAY,-2,GETDATE()), DATEADD(MINUTE,-30,GETDATE())) OR TransferTime IS NULL) AND zone<>199 and authority<>255', $_SESSION['strAccountID'], $character);
如果重要,我使用MSSQL Server 2005。 我真的很感激任何回应。
答案 0 :(得分:0)
而不是 if then else 使用 CASE WHEN
((TransferTime&lt; p.strAccountID为NULL时的情况 那么DATEADD(DAY,-2,GETDATE())ELSE DATEADD(MINUTE,-30,GETDATE())END) 或TransferTime IS NULL)
同样完全符合您的选择条款以避免模糊列问题。尝试像
这样的东西SELECT u.Class,u.Race,u.Strong,u.Sta,u.Dex,u.Intel,u.Cha,u.Points,u.TransferTime
你的ON子句看起来也不错。