我有一个PHP脚本应该根据MS SQL数据库生成图像(特别是我们一年级学生的问候卡)。出于某种原因,在结果资源中的行用完之后,mssql_fetch_array()返回到结果的开头而不是返回false。谁能告诉我为什么会这样呢?
实际的消息是在服务器上的.txt文件中,因为MS SQL Server习惯于破坏标点符号。数据库字段为id | fname | sname | tutgrp | house
。
代码的相关部分:
$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);
}
答案 0 :(得分:0)
将您的时间改为:
while($row = mssql_fetch_assoc($result))
您使用的是False,而不是false,这会导致问题。
答案 1 :(得分:0)
我认为典型的惯例只是
while($row = mssql_fetch_assoc($result))