PHP MySQL小查询超时,必须将限制设置为10
在调用mysql_query()进行相对较小的查询时,我收到了PHP超时错误,因此我必须将限制设置为10.
I am getting PHP timeout errors when calling mysql_query() for a relatively small query, so i have to set the limit to 10.
Fatal error: Maximum execution time of 120 seconds exceeded in C:\xampp\htdocs\data.php on line 19
我已经从代码中删除了循环,代码似乎挂在了mysql_query()函数上.
I have removed the loop from the code, the code seems to hang at the mysql_query() function..
mysql_connect("192.168.50.250",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT T.Tag as 'Device', y.alarmdesc as 'AlarmType', a.Active, a.Cleared FROM gencore.gc_alarms a JOIN ist.Tree T ON(T.DeviceId = a.DeviceId) JOIN GenCore.gc_alarmtypes y ON (a.alarmType = y.aid) LIMIT 10";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table class="sortable resizable editable tableStyle2">
<tr class="headerStyle">
<th>Device</th>
<th>AlarmType</th>
</tr>
<?php
$i=0;
while ($i < $num)
{
$f1=mysql_result($result,$i,"Device");
$f2=mysql_result($result,$i,"AlarmType");
?>
<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
</tr>
<?php
$i++;
}
?>
</body>
</html>
查询从其他任何地方执行都非常快,只有340行,有人 任何指针如何从数据库中检索小表?
The query executes very quick from anywhere else, and is only 340 rows, does anyone have any pointers how to retrieve the small table from the DB?
问候 约翰
您可以使用php.ini
中的mysql.connect_timeout
键延长超时时间.
You can extend the timeout with mysql.connect_timeout
key in php.ini
.
我还注意到mysql_close()
应该在使用mysql_result
之后定位,并且您有错别字:mysql_numrows
应该是mysql_num_rows
I also notice that mysql_close()
should be positioned after using mysql_result
, and you have a typo: mysql_numrows
should be mysql_num_rows