Note that there are some explanatory texts on larger screens.

plurals
  1. POGet all data from DB using fetchall_hashref
    primarykey
    data
    text
    <p>I am using fetchall_hashref to get data satisfying a condition from a mysql DB.The data retrieved will be stored in a hash and then be used futhur by a javascript function.</p> <p>I want to retrieve all the rows of 3 columns and store it in a hash but not being able to do that.</p> <p>The table structure..</p> <p><a href="https://i.stack.imgur.com/1QRn4.png" rel="nofollow noreferrer">table structure</a> <img src="https://i.stack.imgur.com/UeTFE.png" alt="table structure"></p> <p>the table data..</p> <p><a href="https://i.stack.imgur.com/Oba8f.png" rel="nofollow noreferrer">table data</a> <img src="https://i.stack.imgur.com/UeTFE.png" alt="table data"></p> <p>the code being used..</p> <pre><code>#!/usr/bin/perl -w #print "Content-type: text/html\n\n"; use DBI; use CGI; use strict; use warnings; use diagnostics; use Data::Dumper; use CGI::Carp qw (fatalsToBrowser); my $q = CGI-&gt;new; print $q-&gt;header; my $dsn = "DBI:mysql:Demo:localhost"; # Data source name my $username = "mint"; # User name my $password = "MINT123"; # Password my $dbh; my $sth; my $b; my $c; # Database and statement handles $dbh = DBI-&gt;connect($dsn, $username, $password); my $hash = $dbh-&gt;selectall_hashref("SELECT `desc`,date1,riskval from FIR2 where date1 between date_sub(now(),INTERVAL 1 WEEK) and now() order by date1", 'riskval'); print Dumper($hash); $b=join(",",$hash); delete $_-&gt;{riskval} for values %$hash; $dbh-&gt;disconnect(); </code></pre> <p>The output i am getting in browser...</p> <p><img src="https://i.stack.imgur.com/UeTFE.png" alt="browser output"></p> <p>the output in putty..</p> <p><img src="https://i.stack.imgur.com/Ff3pA.png" alt="enter image description here"></p> <p>As you can see I want to print the row where "riskval" is null,the value of "riskval" is 5 in 2 places but only 1 row is getting printed..</p> <p>after i replaced selectall_hashref with selectall_arrayref i got the following error message in putty..</p> <p><img src="https://i.stack.imgur.com/aK6kD.png" alt="second error message"></p> <p>Please help..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload