pdo准备语句语法错误

时间:2016-02-29 00:48:49

标签: php sql pdo

我试图使用预准备语句作为数据库对象的一部分从数据库表的所有行获取所有数据,但我不断收到SQL语法错误。在使用预准备语句切换到PDO之前,我使用的是没有预处理语句的mysqli,我没有错误。我已多次搜索,但无法弄清楚需要改变什么。任何帮助表示赞赏。

public function GetGuestList($eventCode) {
  $this->eventCode = $eventCode;

  //Get event info using prepared statement
  if ($this->stmt = $this->dbConnect->prepare("SELECT * FROM :eventcode")) {
    $this->stmt->bindParam('eventcode', $this->eventCode);
    $this->stmt->execute();
    $this->guestList = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
  }

//return event ifno as array
return $this->guestList;
}

我得到的错误是

Warning:  PDOStatement::execute(): 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 'NULL' at line 1 in /var/www/html/rsvp/lib/classes.php

0 个答案:

没有答案