mysqlperldbiactiveperl

Why don't I get output for this DBI/MySQL query?


I have written the following code in Perl. I have ActivePerl 5.14 for Windows 7.

#!C:\perl64\bin\perl.exe -wT
use strict;
use warnings;
use DBI;
print "Content-type: text/html \n\n";

# MYSQL CONFIG VARIABLES
my $driver     = "mysql";
my $database   = "test555";
my $tablename3 = "test77";

my $user = "root";
my $pw   = "root";

# PERL MYSQL CONNECT()
my $dbh = DBI->connect("DBI:$driver:$database", $user, $pw,);

my $sth = $dbh->prepare("
        SELECT *
          FROM t6
         WHERE paragraph='PWE1234'
    ");

$sth->execute();
#$dbh->disconnect;
#exit 0;

When the program reaches $dbh->disconnect, the system is throwing an error; hence commented it out. When I comment that out, the system is not throwing any error, but neither do I get output.

There is a result for this query, I checked with MySQL once separately.


Solution

  • There is no output because you have no code to create any output.

    After calling execute you need to call one of the fetchsomething methods and do something with the data structure you get back.