My problem is that I can't get placeholders to work in my SQL statements. Specifically, in the below code, when I replace the placeholder ':tripsid'
with a value like 'abcdefg'
the TABLE isn't being created as intended.
SQL Error is:
PDO::errorInfo(): Array ( [0] => 42000 [1] => 1064 [2] => 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 *''sdfghjk' ( id INT NOT NULL, stop_start SMALLINT NOT NULL, stop_end SMA'* at line 1 )
And the code:
// My method to create a table with PDO and placeholders
public function routes_table() {
$this->connect();
$STH = $this->DBH->prepare('CREATE TABLE IF NOT EXISTS :tripsid (
id INT NOT NULL,
stop_start SMALLINT NOT NULL,
stop_end SMALLINT NOT NULL,
distance SMALLINT NOT NULL,
duration TINYINT NOT NULL,
medium TINYTEXT NOT NULL,
CONSTRAINT pk_routes PRIMARY KEY ( id )
)');
$tripsid = "sdfghjk";
$STH->bindParam(':tripsid', $tripsid, PDO::PARAM_STR, 7);
$STH->execute();
// SQL Errors
if (!$STH->execute($input)) {
echo "\nPDO::errorInfo():\n";
print_r($STH->errorInfo());
}
$this->disconnect();
}
I have tried everything I could think of. Does anyone see the mistake?