私は以下のコードを持っており、データベースとして変数を渡す必要があります。データベースとして変数を渡すことは可能ですか?mysqlを使ってストアド変数をデータベースとして渡すには?
私の変数:
my $num_site = join('_', 'rate', $site, '1m');
my $num_site1=join('_','rate',$site,'current');
私のコード:ここで
は私の代わりに、データベース名の行う接続内部変数を渡す代わりに、私はこの方法に従ってくださいdirectly.Canデータベースを与える変数を渡そうとしました私の変数($ num_site)と($ num_site1)をデータベースに渡すのを助けてくれますか?
$DBH=DBI->connect($database) or die "cannot connect to the sql server\n";
$DBH->do("USE $num_site");(can i use the variable like this to fetch the database).
#$DBH->do("use rate_bangalore_1m");
$stmt = "INSERT INTO $num_site.m_status(time,available,closed,used,busy,reserved,down) VALUES(\"$current_time\",\"$ma{'D'}\",\"$ma{'B'}\",\"$ma{'A'}\",\"$ma{'C'}\",\"$ma{'R'}\",\"$ma{'+'}\")";
print "\n $stmt \n";
my $sth = $DBH->prepare($stmt);
$sth->execute() or print "Could not insert data";
$sth->finish;
$DBH->disconnect();