我目前正在处理perl script
。
Select Column1,Column2,Column3.. from table.
此查询包含$cmd="Select Column1 ";
中的部分内容
和其他$cmd1=",Column2,Column3 from table"; // This is dynamic part, so split query in two different variable.
执行整个查询后。
如何执行此查询拆分部分。?
答案 0 :(得分:-1)
use DBI;
use strict;
use warnings;
# Your input !
my $cmd = "Select Column1 ";
my $cmd1 = ",Column2,Column3 from table";
# I am wondering why you have your query like this ...
# but anyway, lets assume there's a reason behind this!
my $dbh =
DBI->connect(
'DBI:mysql:databasename;host=db.example.com', # TODO Change this
'username', # TODO change this
'password', # TODO change this
{ RaiseError => 1 }
) or die "Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare( $cmd . $cmd1 );
$sth->execute();
my @row;
while ( @row = $sth->fetchrow_array ) {
print "@row\n";
}