0

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
Dino Morrison
  • 97
  • 2
  • 8
  • I've encountered the same problem. (As I know) you can't bind a tablename as Param. Additional you have to name your param ":eventcode" not "eventcode" – Petschko Feb 29 '16 at 00:58
  • Can't bind the table param. – Darren Feb 29 '16 at 01:02
  • 1
    Look also here: http://stackoverflow.com/questions/182287/can-php-pdo-statements-accept-the-table-or-column-name-as-parameter – Petschko Feb 29 '16 at 01:04

0 Answers0