1

我收到此错误:

Warning: PDO::query() [pdo.query]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'When, RDV, Comments FROM distributions WHERE IDFond = 1' at line 1 in /Applications/XAMPP/xamppfiles/htdocs/JG/DistributionManager.class.php on line 56

执行此代码时:

$Distribution_Manager->getListByFunds($Selected_Fond->id());

    foreach ($Distribution_Manager as $Distrib)
    {
        echo $Distrib->Comments();
    }

这是相关的功能:

  public function getListByFunds($FundID)
  {
    $Distribution = array();

    $q = $this->_db->query('SELECT id, IDClient, IDFond, Who, When, RDV, Comments FROM distributions WHERE IDFond = '.$FundID);

    while ($donnees = $q->fetch(PDO::FETCH_ASSOC))
    {
      $Distribution[] = new Distribution($donnees);
    }
    return $Distribution;
  }

应该是一个小错误,但我落后了将近 50 分钟!在此先感谢您的帮助 ;)

4

4 回答 4

3

WHENmysql 保留字,因此请尝试使用不同的列名或WHEN用反引号括起来。

于 2012-11-30T10:44:19.793 回答
2

When是mysql关键字,试试这个

SELECT id, IDClient, IDFond, Who, When AS anything..

或将此关键字括在反引号中

SELECT id, IDClient, IDFond, Who, `When`, RDV..
于 2012-11-30T10:45:20.680 回答
0

回馈列名的引号,id然后尝试

于 2012-11-30T10:46:49.430 回答
0

你永远不会在你的陈述中结束你的报价。

于 2012-11-30T16:30:01.687 回答