One other thing that I would change to your code is to add a mysql close statement. This way, you close out the connection that you open when you run the truncate (so as to free up resources). For your code, simply execute at the end:
Code:
mysql_close($db);