From: "Davide Copelli" <[EMAIL PROTECTED]> > I need to execute this query and change the name of the table > > $table1 = 'tab1'; > $table2 = 'tab2'; > $data1 = 'a'; > $data2 = 'b'; > > my $sth = $dbh->prepare(qq|SELECT count(id) FROM ? WHERE data1=? |); > > $sth->execute( $table1,$field1 ); > $total1=$sth->fetchrow_array(); > > $sth->execute( $table2,$field2 ); > $total2=$sth->fetchrow_array(); > > but the error is: > > DBD::mysql::st execute failed: You have an error in your SQL syntax > near ''tab1' WHERE data='a'' at line 1 > > What's wrong ? > > Can I make a placeholder for the name of the table ?
No. You will have to prepare a separate statement for each table: my %sth; $sth{tab1} = $dbh->prepare(qq|SELECT count(id) FROM tab1 WHERE data1=? |); $sth{tab2} = $dbh->prepare(qq|SELECT count(id) FROM tab2 WHERE data1=? |); .... $sth{$table1}->execute($field1 ); $total1=$sth{$table1}->fetchrow_array(); .... Jenda =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]