MySQL Forums
Forum List  »  Perl

table name as variable in INSERT
Posted by: B A
Date: July 31, 2011 08:51AM

hi,

I have the following code:

my $name='Bob';
my $table='test';

my $ins_rec="INSERT INTO test (symbol) VALUES(\'$name\');";

when I run this from perl, it works fine.

however, when I try to replace test with the variable as below,

my $ins_rec="INSERT INTO \'$table\' (symbol) VALUES(\'$name\');";

it gives me the following error:
DBD::mysql::st execute failed: 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 ''test' (symbol) VALUES('Bob')'

so, that means it is still reading $table as test, but I have made some syntax error somewhere?
Can you please help me fix it. thanks!

Options: ReplyQuote


Subject
Written By
Posted
table name as variable in INSERT
B A
July 31, 2011 08:51AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.