在下面的代码中,我浏览了一个看起来像这个
的mysqli-table dspid,url,image(blob)
目标是查找所有不包含图像(blob)的条目,并将url(图像URL)转换为blob,并使用图像中的blob更新条目(此处省略,在//无结果中完成)。如果在另一个条目中有相同的url我只是从那里复制图像(blob)。以下代码就是这样做的,但是大约1分钟后,该过程以500错误中止。
这个错误来自哪里,是否有更快/更有效的方法来完成任务(它占用了我65%的处理能力)?
<?
$sql = "SELECT url,id
FROM `dsp`
WHERE `image` IS NULL
ORDER BY `dsp`.`id` ASC";
if ($result = mysqli_query($link, $sql)) //$link is a mysqli object
{
while ($row = mysqli_fetch_row($result))
{
$sqli = "SELECT `image`,`image_type`
FROM `dsp`
WHERE `image` IS NOT NULL
AND `url` = '".$row[0]."'
ORDER BY `dsp`.`image` DESC";
$result2 = $link->query($sqli);
if ($result2->num_rows > 0 )
{
$row2 = $result2->fetch_row();
$image = mysql_escape_string($row2[0]);
$image_typ = $row2[1];
$sqli = "UPDATE `dsp` SET `image` = '".$image."', `image_type` = '".$image_typ."' WHERE `dsp`.`id` =".$row[1].";";
$link->query($sqli);
//echo $sqli;
if ($link->error != '')
{
die($link->error);
}
}
else
{
//no result
}
}
}
mysqli_close($link);
?>