Reputation: 65
I want to create a table by the name of the number that user creates. So what I wrote as the Postgres query is
$sql = 'CREATE TABLE '.$rNumber.'_Bus_Stops(
id serial primary key,
name character varying,
x double precision,
y double precision
);';
I'm getting this error.
Warning: pg_query(): Query failed: ERROR: syntax error at or near "11" LINE 1: CREATE TABLE 11_Bus_Stops( ^ in C:\wamp\www\cdap4\route1.php on line 138
Tried the same with double quotes as well. It does not work. Can someone help? It works totally fine if I remove $rNumber
Upvotes: 0
Views: 341
Reputation: 246278
Since the table name starts with a digit, it has to be a quoted identifier (an identifier surrounded with double quotes):
$sql = 'CREATE TABLE "'.$rNumber.'_Bus_Stops" (
Upvotes: 1