Hi everybody,
I am having a problem with binding a variable when executing on a DBI
object. The code goes:
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
#DBI variables
my $database = 'databaseName';
my $hostname = 'localhost';
my $dsn = "DBI:mysql:database=$database;host=$hostname";
my $dbh = DBI->connect($dsn, 'user', 'notMyPassword', {RaiseError=>1}) ||
die "Database connection not made : $DBI::errstr";
my $select = $dbh->prepare_cached("select * from ?");
die "Couldn't prepare queries\n" unless defined $select;
$select->execute('tableName');
while (my $row = $select->fetchrow_arrayref()){
print "@$row\n";
}
$dbh->disconnect();
However I get the 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 ''tableName'' at line 1 at ./haha.pl line 16.
If I change the bind variable to tableName in the SQL and just do
$select->execute(), then it works.
Any ideas?
Many thanks,
Dave
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/