如何从 Perl 的 DBI 获取 MySQL 查询的结果?
我正在执行以下操作,并得到“1”,我认为这意味着该语句进展顺利。但我想要结果。
怎么了?
#!/usr/bin/perl
use strict;
use DBI;
my $host = "test";
my $database = "dd";
my $port = 3306;
my $user = "uuu";
my $pw = "ppp";
my $mysql = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port", $user, $pw)
or die "Cannot connect to MySQL server\n";
my $m = $mysql->do(qq{select MAX(idvisit) from log_visit});
print $m;
I am doing the following, and getting "1" which I assume means the statement wend well. But I would like the result instead.
What's wrong?
#!/usr/bin/perl
use strict;
use DBI;
my $host = "test";
my $database = "dd";
my $port = 3306;
my $user = "uuu";
my $pw = "ppp";
my $mysql = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port", $user, $pw)
or die "Cannot connect to MySQL server\n";
my $m = $mysql->do(qq{select MAX(idvisit) from log_visit});
print $m;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查文档以了解您遇到问题的功能总是值得的。
在这种情况下,“do”的 DBI 文档 说:
而且,更明确地说,
It's always worth checking the documentation for functions that you're having trouble with.
In this case the DBI documentation for "do" says:
And, more explicitly,
do
返回受影响的行数。您可能想查看statement
类,特别是execute
函数。do
returns the number of affected rows. You might want to look into thestatement
class and specifically, theexecute
function.