Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

perl hangs with a simple mySQL query

by chuck (Initiate)
on Nov 19, 2014 at 20:59 UTC ( [id://1107823]=perlquestion: print w/replies, xml ) Need Help??

chuck has asked for the wisdom of the Perl Monks concerning the following question:

I have written a Perl script to schedule appointments at a clinic. The code puts clients in timeslots for every clinic day. There is a MySQL query that simply gets the nurse names and IDs then makes a drop-down select button beside the client's names in the schedule. When there is more than 9 people scheduled for the day the query hangs the script. It also hangs if there are more that 3 people with the same appointment time and more than 5 people in total for that day. I am completely baffled at why this script would hang under those specific circumstances, especially considering that this section of code has nothing to do with the appointment tables - it only uses the nurses table. Here is the section of code. If I comment out the stuff during the query (in the while loop) it works fine but with no nurse drop-down menu. If I do *ANYTHING* inside the while loop the code hangs. The query works fine under PHPMyAdmin.

if ($in{clinicdate} <= $today) { my $query="SELECT nurseid, fname, lname FROM nurses ORDER BY fname + ASC;"; my $dbh; my $sth; $dbh = DBI->connect("DBI:mysql:$dbname", $dbuser, $dbpass,{PrintEr +ror => 1, RaiseError => 1}); $sth=$dbh->prepare($query); $sth->execute(); print "$formstart\n\t\t<INPUT TYPE=HIDDEN NAME=\"f\" VALUE=\"Chang +eNurse\">\n\t\t\t<INPUT TYPE=HIDDEN NAME=\"clinicdate\" VALUE=\"$in{c +linicdate}\">\n\t\t\t<INPUT TYPE=HIDDEN NAME=\"clientid\" VALUE=\"$cl +ientid\">\n\t\t<SELECT NAME=\"nurseused\" onchange=\"this.form.submit +()\">\n\t\t\t<OPTION VALUE=\"\">Nurse</OPTION>"; while (@row=$sth->fetchrow()) { print "\n\t\t\t<OPTION VALUE=\"$row[0]\""; if ($nurseused{$clientid} eq $row[0]) { print " SELECTED"; } print ">$row[1] $row[2]</OPTION>"; } $sth->finish; $dbh->disconnect; print "\n\t\t\t<OPTION VALUE=\"0\" style=\"background-color:red\"> +NO SHOW!</OPTION>\n\t\t</SELECT>\n</FORM>"; } else { if ($confirmed{$clientid}==1) { print " X "; } }

Replies are listed 'Best First'.
Re: perl hangs with a simple mySQL query
by Loops (Curate) on Nov 19, 2014 at 21:17 UTC

    When you say "hang", do you mean you have to kill the process, or the client browser hangs? Is it possible that some of that data that you're including directly from the database is being misinterpreted as the start of a string, or other HTML element? In any case you should probably be escaping them with something like HTML::Escape.

    What happens if you replace fetchrow() in the while loop with something that just supplies test data from an array?

      Okay, it must have been a problem with the server. I switched to another webhosting service and the exact same code works fine. Thanks for the help everyone!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1107823]
Approved by Loops
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found