select col1 from 'foo' where col1 = '3'
####
mysql> use test;
mysql> create table foo (col1 integer);
mysql> insert into foo values (1),(2),(3);
#!/usr/bin/perl -wls
use strict;
use warnings;
our $user ||= undef;
our $pass ||= undef;
use DBI;
my $dbh = DBI->connect(q{DBI:mysql:test}, $user, $pass)
or die "connect failed";
my $sth = $dbh->prepare("select col1 from ? where col1 = ?");
$sth->trace( 2 );
my $table = 'foo';
my $value = 3;
$sth->execute($table, $value) or die("execute failed");
__END__
$ ./646467.pl -user ***** -pass *****
mysql_st_internal_execute MYSQL_VERSION_ID 40120
Binding parameters: select col1 from 'foo' where col1 = '3'
--> do_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 ''foo' where col1 = '3'' at line 1 error 1064 recorded: 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 ''foo' where col1 = '3'' at line 1
<-- do_error
##
##
#!/usr/bin/perl -wls
use strict;
use warnings;
our $user ||= undef;
our $pass ||= undef;
use DBI;
my $dbh = DBI->connect(q{DBI:mysql:test}, $user, $pass)
or die "connect failed";
my $table = 'foo';
my $sth = $dbh->prepare("select col1 from $table where col1 = ?");
my $value = 3;
$sth->execute($value) or die("execute failed");
while (my $href = $sth->fetchrow_hashref()) {
foreach my $key (keys %{$href}) {
print qq{$key: } . $href->{$key};
}
}
$sth->finish();
$dbh->disconnect();
__END__
$ ./646467.pl -user ***** -pass *****
col1: 3
##
##
mysql Ver 14.7 Distrib 4.1.20, for redhat-linux-gnu (i686) using readline 4.3
Linux 2.6.9 i686
Module id = DBI INST_VERSION 1.56