下面的代码是用于更新mySQLdatabase的php文件的一部分。
在FF Firebug控制台中,我可以看到POST数据在提交到这个php文件的表单中都是正确的。
问题是,如果$i大于3,则会出现以下错误:
连接被重置
在加载页面时重置到服务器的连接。“
这是否意味着我必须编写一个自定义php.ini?如果是的话,我需要增加哪些值?
我知道我的循环mysql_query代码也可能是不正确的,但是它确实适用于1到3的$i值。如果是这样的话,有人能建议正确的编码吗?
for ($i=1; $i<=$rr_years; $i++){
$idrr = GetSQLValueString($_POST['id' . $i], "int");
$associated_horse = GetSQLValueString($_POST['associated_horse' . $i], "int");
$year = GetSQLValueString($_POST['year' . $i], "text");
$age = GetSQLValueString($_POST['age' . $i], "int");
$starts = GetSQLValueString($_POST['starts' . $i], "int");
$first = GetSQLValueString($_POST['first' . $i], "int");
$first_sw = GetSQLValueString($_POST['first_sw' . $i], "int");
$second = GetSQLValueString($_POST['second' . $i], "int");
$second_sp = GetSQLValueString($_POST['second_sp' . $i], "int");
$third = GetSQLValueString($_POST['third' . $i], "int");
$third_sp = GetSQLValueString($_POST['third_sp' . $i], "int");
$age_notes = GetSQLValueString($_POST['age_notes' . $i], "text");
$age_text = GetSQLValueString($_POST['age_text' . $i], "text");
$earned = GetSQLValueString($_POST['earned' . $i], "text");
mysql_select_db($database_HDAdave, $HDAdave);
mysql_query("UPDATE race_records SET
associated_horse = $associated_horse,
year = $year,
age = $age,
starts = $starts,
first = $first,
first_sw = $first_sw,
second = $second,
second_sp = $second_sp,
third = $third,
third_sp = $third_sp,
age_notes = $age_notes,
age_text = $age_text,
earned = $earned
WHERE rr_id = $idrr", $HDAdave) or die(mysql_error());
}谢谢你能提供的任何帮助。
发布于 2011-12-22 06:40:00
这可能是个人喜好,而不是真正的性能问题,但是GetSQLValueString() (对于那些好奇的人来说,这是在使用Dreamweaver的数据库帮助时生成的宏媒体DW的自定义函数。在这个SO question中,它显示并解释了)有时是“太多”,而简单的mysql_real_escape_string()或检查值是否为INT就足够了。
另外,我会将连接和数据库的选择放在循环之外。此外,通常不需要它,您可以在每篇文章之后释放mysql结果:
// connect to DB here.
mysql_select_db($database_HDAdave, $HDAdave);
for ($i=1; $i<=$rr_years; $i++){
$idrr = intval($_POST['id' . $i]);
$associated_horse = intval($_POST['associated_horse' . $i]);
$year = mysql_real_escape_string($_POST['year' . $i]);
$age = intval($_POST['age' . $i]);
$starts = intval($_POST['starts' . $i]);
$first = intval($_POST['first' . $i]);
$first_sw = intval($_POST['first_sw' . $i]);
$second = intval($_POST['second' . $i]);
$second_sp = intval($_POST['second_sp' . $i]);
$third = intval($_POST['third' . $i]);
$third_sp = intval($_POST['third_sp' . $i]);
$age_notes = mysql_real_escape_string($_POST['age_notes' . $i]);
$age_text = mysql_real_escape_string($_POST['age_text' . $i]);
$earned = mysql_real_escape_string($_POST['earned' . $i]);
mysql_query("UPDATE `race_records` SET
`associated_horse` = $associated_horse,
`year` = '$year',
`age` = $age,
`starts` = $starts,
`first` = $first,
`first_sw` = $first_sw,
`second` = $second,
`second_sp` = $second_sp,
`third` = $third,
`third_sp` = $third_sp,
`age_notes` = '$age_notes',
`age_text` = '$age_text',
`earned` = '$earned'
WHERE `rr_id` = $idrr", $HDAdave) or die(mysql_error());
// not needed:
mysql_free_result($HDAdave);
}
?>发布于 2011-12-22 06:31:59
错误文本The connection to the server was reset while the page was loading.告诉我,错误发生在web服务器和客户机(浏览器)之间,而不是web服务器和DB之间。
您看过数据库并查看记录是否被正确更新了吗?
作为可能的解决办法:
此外,InnoDB存储引擎可能在这里帮助您,因为它具有行级锁定,并且它可能减少DB级别上的执行。
另外,查看apache的错误日志,看看是否还有其他错误。
https://stackoverflow.com/questions/8600089
复制相似问题