0

以下は、mysqlデータベースに接続し、perlを使用して結果を取得するためのコードです。

次の例では、サンプルテーブルに10列あります。レコード99の2番目と3番目の列を変数に入れたいだけです。

誰かがこれで私を助けることができますか?

use strict;
 use warnings;
 use DBI;

my $dbh = DBI->connect('dbi:mysql:perltest','root','password') or die "Connection Error: $DBI::errstr\n";
my $sql = "select * from samples where record='99'";
my $sth = $dbh->prepare($sql);
$sth->execute or die "SQL Error: $DBI::errstr\n";
while (my @row = $sth->fetchrow_array) {
 print "@row\n";
 } 

前もって感謝します

4

1 に答える 1

2

このコードは、行の2番目と3番目の列を変数に変換します。

while (my @row = $sth->fetchrow_array) {
     $var1 = @row[1];
     $var2 = @row[2];
} 
于 2012-11-06T23:10:21.963 に答える