I am trying to get all data from all rows of a database table using a prepared statement as part of a database object, but I keep getting a SQL syntax error. I was using mysqli without prepared statements before switching to PDO with prepared statements and I got no errors. I've searched many times but can not figure out what needs to be changed. Any help is appreciated.
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;
}
And the error Im getting is
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