While working on a project today a script I had that turns a database into a simple tab delimited file stopped working and was producing the following error:
Lost connection to MySQL server during query rows
Google searching didn’t turn up anything useful because most people said just to “use mysqldump instead” which wasn’t really an option for me. After running analyze, repair and optimize table and using phpMyAdmin to make a copy of the table I was pretty confident that it wasn’t a corruption problem so I added the following bit of code around what I already had:
define(‘C_NUM_PER_LIMIT’, 100000);
$iteration = 0;
do
{
$limit_from = C_NUM_PER_LIMIT * $iteration; $iteration++;
$sql = “SELECT * FROM `table` ORDER BY `id` LIMIT $limit_from, ” . C_NUM_PER_LIMIT;
$res = mysql_query($sql);
// way more stuff
} while (mysql_num_rows($res) > 0);
I hope this helps.


