How to get MySQL query results from Perl DBI?

I do the following, and getting “1,” which I suppose means the statement works well. But I would like to get a result.

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;
+3
source share
4 answers
my $m = $mysql->selectrow_array(qq{select MAX(idvisit) from log_visit});
+1
source
my $m = $mysql->prepare("select MAX(idvisit) from log_visit");
$m->execute() or die "Couldn't execute statement: ".$m->errstr;
print $m->fetch()->[0];
+8
source

, .

DBI "do" :

. undef .

, ,

SELECT ( ).

+8

doreturns the number of rows affected. You might want to learn a class statementand, in particular, a function execute.

+3
source

Source: https://habr.com/ru/post/1764333/


All Articles