In the following code I browse a mysqli-table dsp which looks like this
id,url,image(blob)
Goal is to find all entries which do not contain an image(blob) and to convert url(an image url) into blob and update the entry with blob in image(omitted here, done in //no result). If in another entry there's the same url already I just copy the image(blob) from there. The following code does just this but after about 1 minute the process aborts with a 500 error.
Where does this error come from and is there a quicker/more efficient way to do the task(it consumes 65 per cent of my processing power)?
<?
$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);
?>