This is how we achieve -
for ($attempt=0; $attempt<100; $attempt++) {
$result=mysql_query($query, $db);
if (($result===false) && (mysql_errno($db)==1213))
usleep(10000); // dead with InnoDB deadlock errors by waiting 0.01s then retrying
else
break;
}
Now we got the result in $result and we can try the following options -
while ($row=mysql_fetch_row($result)) {
...
}
while ($assoc=mysql_fetch_assoc($result)) {
...
}