开发者

Mysql query killing script

I have a simple query

$sql ="INSERT INTO `table` (`data`, `value`, `name`, `id`) VALUES ".$result."";

$result = "('1', '2', 'John', '123'), (...), ... (...);";

This is data I collect from various places, sometimes I end up with an extra column

$result = "('1', '2', '3', 'John', '123'), (...), ... (...);";

Which returns an error. The problem is that the query is inside a php loop. My script can run for 40/+ min (cron job).

Is there any way of "escaping" this error so that it doesn't kill开发者_C百科 the script?


Try putting a check on the result of your mysql_query, something like:

$ret = mysql_query($sql);
if($ret === false)
{
     // Do something special upon error
}
// Continue executing

That gives you control over any unexpected MySQL issues.

Edit: Also note that you should not end your query with a semi-colon, as per the mysql_query() documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜