mssql_fetch_array not returning false?
I've got a php script that is supposed to generate images base开发者_开发问答d on an MS SQL database (specifically, greetings cards for our first-year students). For some reason, after it runs out of rows in the result resource, mssql_fetch_array() goes back to the start of the result rather than returning false. Can anyone tell me why this could be?
The actual messages are in .txt files on the server, due to MS SQL Server's habit of mangling the punctuation. Database fields are id | fname | sname | tutgrp | house
.
Relevant portion of code:
$dbConn = mssql_connect($dbHost, $dbUser, $dbPass) or die("Connection to database failed");
mssql_select_db($dbData, $dbConn) or die("Unable to select database");
$query = "SELECT * FROM newIntakeTest;";
$result = mssql_query($query, $dbConn) or die("Unable to query");
while(False !== ($row = mssql_fetch_assoc($result)))
{
array_walk($row, 'trim_value');
echo $row["sname"].", ".$row["fname"]."... ";
$image = imagecreatefrompng("res/".$row["house"].".png");
$black = imagecolorallocate($image,0,0,0);
//tutor msg
imagettftext($image, 35, 0, 57, 86, $black, $fontBold, "Message from your Tutor:");
$fn = "in/".$row["tutgrp"].".txt";
$fh = fopen($fn,'r');
$tutormsg = fread($fh,filesize($fn));
fclose($fh);
imagettftext($image, 35, 0, 57, 139, $black, $fontStd, wrap(35,0,$fontStd,$tutormsg,1640));
//HoH msg
imagettftext($image, 35, 0, 57, 1399, $black, $fontBold, "A message from ".$heads[$row["house"]].", Head of ".$row["house"]." house:");
$fn = "in/".$row["house"].".txt";
$fh = fopen($fn,'r');
$headmsg = fread($fh,filesize($fn));
fclose($fh);
imagettftext($image, 35, 0, 57, 1455, $black, $fontStd, wrap(35,0,$fontStd,$headmsg,1640));
printaligned($image, "To: ".$row["fname"]." ".$row["sname"], $fontStd, 70, 450, $black);
printaligned($image, "From: ".substr($row["house"],0,1)."-".$row["tutgrp"], $fontStd, 70, 1985, $black);
printaligned($image, $row["house"]." House", $fontStd, 70, 2130, $black);
imagepng($image,"out/".$row["id"]."_".$row["sname"]."_".$row["fname"].".png");
echo "done.<br />";
imagedestroy($image);
}
Change your while to:
while($row = mssql_fetch_assoc($result))
You are using False, not false - that will cause a problem.
I believe the typical convention is just
while($row = mssql_fetch_assoc($result))
精彩评论