Help us understand the problem. What is going on with this article?

メモ: Perl DBI mysql ROW_NUM

More than 3 years have passed since last update.
use DBI;

my $database = 'my_database';
my $host    = 'localhost';
my $port    = '3308';
my $db_user = 'user';
my $db_pass = 'pass';

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port", $db_user, $db_pass);

my $sth = $dbh->prepare(
'SELECT @rownum:=@rownum+1 as ROW_NUM, TABLE_NAME '.
'FROM information_schema.TABLES A, '.
'(SELECT @rownum:=-1) B '.
'WHERE table_schema=database() '
);
$sth->execute;
for(my $i = 0; $i < $sth->rows; $i++){
    my @row = $sth->fetchrow_array;
    print "\t", $row[0], "\t", $row[1], "\n";
}
$sth->finish;
$dbh->disconnect;

参考ページ
MySQLのSELECT結果に行番号を振る。

SET @rownum := -1;使うと怒られるんじゃー!

C#だと"Allow User Variables=True"SETが使えるんだそうな。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away