Reputation: 17
First, I have weak eng skill.
(Using mysql module)
I want create tables (5 tables) with same column
but i have error message that
Error: ER_PARSE_ERROR: 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 ''pre'( R varchar(5), Name varchar(20), Team varchar(20), Age varchar(5), Positio' at line 1
my code is here
post=['pre','b','c','d','e'];
conn.query('create table ?(\
R varchar(5), Name varchar(20), Team varchar(20), Age varchar(5), Position varchar(20), Apps varchar(5), Yel varchar(5) , Red varchar(5), AerialsWon varchar(5), MotM varchar(5), \
Tackles varchar(5), Inter varchar(5), Fouls varchar(5), Offsides varchar(5), Clear varchar(5), OwnG varchar(5),\
Goals varchar(5),SpG varchar(5), Drb varchar(5), Fouled varchar(5), Off varchar(5), Disp varchar(5),\
Assists varchar(5), KeyP varchar(5), AvgP varchar(5), PsR varchar(5), Crosses varchar(5),Thrb varchar(10))', post, function(err, rows, fields) {
if (err) throw err;
console.log('//2.Create pre table');
});
When I insert value , (? and post array ) running . but (? and post array ) don't working in table name.
Upvotes: 0
Views: 452
Reputation: 155
Yes, it's impossible. But you can use string concatenation:
var table_name = 'pre';
var query = 'CREATE TABLE ' + table_name + '...';
The rest would stay as previous.
Upvotes: 1